olivier 0 Posted November 17, 2012 Report 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. Quote Link to post Share on other sites
Edward 108 Posted November 18, 2012 Report 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'; Quote Link to post Share on other sites
Larry 428 Posted November 20, 2012 Report Share Posted November 20, 2012 Thanks for the suggestion, Olivier. I've added a note about that. Quote Link to post Share on other sites
Ziggi 5 Posted December 8, 2012 Report 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... Quote Link to post Share on other sites
Solid 0 Posted December 10, 2012 Report Share Posted December 10, 2012 Agree Ziggi and oliver, thats the hardest thing for me to grasp aswell. Good suggestion. Quote Link to post Share on other sites
Ziggi 5 Posted December 10, 2012 Report 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 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.