note 72440 added to function.get-class
| From: | yichengzero-fouratgmaildotcom at osu1 dot php dot net | Date: | Thu, 18 Jan 2007 20:22:22 +0000 |
| Subject: | note 72440 added to function.get-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121902@lists.php.net to get a copy of this message | ||
This a response to luke at liveoakinteractive dot com and davidc at php dot net. Static methods and
variables, by definition, are bound to class types not object instances. You should not need to
dynamically find out what class a static method belongs to, since the context of your code should
make it quite obvious. Your questions reveals that you probably don't quite understand OOP
quite yet (it took me a while as well).
Luke, the observed behavior from your particular code snippet makes perfect sense when you think
about it. The method getclass() is defined in BooBoof, so the __CLASS__ macro would be bound to
BooBoof and defined in relation to the BooBoof class. The fact that CooCoof is a subclass of
BooBoof just means that it gains a shortcut to BooBoof::getclass(). So, in effect, you are really
asking (in a convoluted way): "What is the class to which belongs the method call
BooBoof::getclass()?" The correct solution (if you actually want/need to do this) is to simply
implement CooCoof::getclass() { return __CLASS__; } inside of the CooCoof definition, and any
childclasses that you want to mimic this behavior. CooCoof::getclass() will have the expected
behavior.
----
Server IP: 216.194.113.175
Probable Submitter: 208.49.175.66
----
Manual Page -- http://www.php.net/manual/en/function.get-class.php
Edit -- https://master.php.net/note/edit/72440
Del: integrated -- https://master.php.net/note/delete/72440/integrated
Del: useless -- https://master.php.net/note/delete/72440/useless
Del: bad code -- https://master.php.net/note/delete/72440/bad+code
Del: spam -- https://master.php.net/note/delete/72440/spam
Del: non-english -- https://master.php.net/note/delete/72440/non-english
Del: in docs -- https://master.php.net/note/delete/72440/in+docs
Del: other reasons-- https://master.php.net/note/delete/72440
Reject -- https://master.php.net/note/reject/72440
Search -- https://master.php.net/manage/user-notes.php