Using Instance of a Class


If I have written a new class and typically use it by doing something like:

$instance = new MyClass;


I remember seeing somewhere out here where this can be executed using one line code rather than the 2 above.  Something like Yii::->MyClass->getWhatever, but I can't seem to find anything out here.  Am I correct in that this can be done without having to first create an instance and then use the instance?



Are you referring to application component? You can configure it in 'components' and then use it with Yii::app()->componentName->methodName().

If not, you can use Yii::createComponent('MyClass')->methodName();

That is what I was looking for.  Thanks Qiang!