> Info: While the approach of calling [[Yii::createObject()]] looks more complicated, it is more powerful due to
> Info: While the approach of calling [[Yii::createObject()]] looks more complicated, it is more powerful because it is implemented on top of a [dependency injection container](concept-di-container.md).
the fact that it is implemented on top of a [dependency injection container](concept-di-container.md).
The [[yii\base\Object]] class enforces the following object lifecycle:
The [[yii\base\Object]] class enforces the following object lifecycle:
...
@@ -90,5 +89,5 @@ The [[yii\base\Object]] class enforces the following object lifecycle:
...
@@ -90,5 +89,5 @@ The [[yii\base\Object]] class enforces the following object lifecycle:
3. Post-initialization within [[yii\base\Object::init()|init()]]. You may override this method to perform sanity checks and normalization of the properties.
3. Post-initialization within [[yii\base\Object::init()|init()]]. You may override this method to perform sanity checks and normalization of the properties.
4. Object method calls.
4. Object method calls.
The first three steps all happen within the object's constructor. This means that once you get an object instance,
The first three steps all happen within the object's constructor. This means that once you get a class instance (i.e., an object),
it has already been initialized to a proper state that you can reliably work with.
that object has already been initialized to a proper, reliable state.