olivier Posted November 17, 2012 Share Posted November 17, 2012 Dear Larry, p13 : $obj = new SomeClass(); $obj->doThis(); p 53: $app = Yii::createWebApplication($config); $app->run(); I Searched on the Internet and found the explanation about Static methods, but maybe you could add a short explanation p13 about this ? I found a clear answer here http://stackoverflow.com/questions/3961456/difference-double-colon-and-arrow-operators-in-php my 2 cents... Thanks for reading. Olivier. Link to comment Share on other sites More sharing options...
Edward Posted November 18, 2012 Share Posted November 18, 2012 Static methods can be called directly from a class without having to make an instance of it with the new keyword. So its similar to calling a function but instead you need to call it via the class name with scope resolution operator "::" followed by the method name. For example Class Edward { static public function GetName() { echo "My name is Edward"; } } Edward::GetName(); // Echo's 'My name is Edward'; Link to comment Share on other sites More sharing options...
Larry Posted November 20, 2012 Share Posted November 20, 2012 Thanks for the suggestion, Olivier. I've added a note about that. Link to comment Share on other sites More sharing options...
Ziggi Posted December 8, 2012 Share Posted December 8, 2012 Larry - as a relatively new Yii user I find one of the most difficult part of the game finding how given class can be addressed. I mean - it is often difficult to guess how to use given class' method in the application scope as it is often unclear is given class already instancialized or not, should given method be called statically or rather through an object, etc. You may see very often people asking questions like "how to call a method of one controller from another one" etc. This is all about the issue I tried to describe above. I do not know is it possible to give some general advices how to read documentation to resolve such issues but perhaps you know better and can share... Link to comment Share on other sites More sharing options...
Solid Posted December 10, 2012 Share Posted December 10, 2012 Agree Ziggi and oliver, thats the hardest thing for me to grasp aswell. Good suggestion. Link to comment Share on other sites More sharing options...
Ziggi Posted December 10, 2012 Share Posted December 10, 2012 The real problem is documentation, where way of invoking is never mentioned and only through tiresome and tedious code reverse-engineerng one may learn for instance that controller's actions are actually created using reflection - so no wonder it's impossible to create new action dynamically (in runtime) using any "regular" measure. Though Yii documentaion is extraordinary complete as for open-source project standards - it lacks information about class invoking and delegates the task to personal experience of Yii users. Unfortunately, this style very often renders community input difficult to read by a novice users as though one my learn on various fora how to "extend" given class - he or she still remains in state of perfect confusion: "but how the hell shall I invoke this class to apply one of its great methods in my particular case???". Best regards, Ziggi 1 Link to comment Share on other sites More sharing options...
Recommended Posts