note 113231 added to language.oop5.paamayim-nekudotayim
| From: | guy at syntheticwebapps dot com | Date: | Sun, 15 Sep 2013 20:29:26 +0000 |
| Subject: | note 113231 added to language.oop5.paamayim-nekudotayim | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-196265@lists.php.net to get a copy of this message | ||
It seems as though you can use more than the class name to reference the static variables,
constants, and static functions of a class definition from outside that class using the :: . The
language appears to allow you to use the object itself.
For example:
class horse
{
static $props = {'order'=>'mammal'};
}
$animal = new horse();
echo $animal::$props['order'];
// yields 'mammal'
This does not appear to be documented but I see it as an important convenience in the language. I
would like to see it documented and supported as valid.
If it weren't supported officially, the alternative would seem to be messy, something like
this:
$animalClass = get_class($animal);
echo $animalClass::$props['order'];
----
Server IP: 69.147.83.199
Probable Submitter: 70.123.131.58
----
Manual Page -- http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php
Edit -- https://master.php.net/note/edit/113231
Del: integrated -- https://master.php.net/note/delete/113231/integrated
Del: useless -- https://master.php.net/note/delete/113231/useless
Del: bad code -- https://master.php.net/note/delete/113231/bad+code
Del: spam -- https://master.php.net/note/delete/113231/spam
Del: non-english -- https://master.php.net/note/delete/113231/non-english
Del: in docs -- https://master.php.net/note/delete/113231/in+docs
Del: other reasons-- https://master.php.net/note/delete/113231
Reject -- https://master.php.net/note/reject/113231
Search -- https://master.php.net/manage/user-notes.php