note 51484 added to language.oop5.static
| From: | michalf at ncac dot torun dot pl | Date: | Thu, 31 Mar 2005 22:42:09 +0000 |
| Subject: | note 51484 added to language.oop5.static | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87294@lists.php.net to get a copy of this message | ||
Inheritance with the static elements is a nightmare in php. Consider the following code:
<?php
class BaseClass{
public static $property;
}
class DerivedClassOne extends BaseClass{
}
class DerivedClassTwo extends BaseClass{
}
DerivedClassOne::$property = "foo";
DerivedClassTwo::$property = "bar";
echo DerivedClassOne::$property; //one would naively expect "foo"...
?>
What would you expect as an output? "foo"? wrong. It is "bar"!!! Static
variables are not inherited, they point to the BaseClass::$property.
At this point I think it is a big pity inheritance does not work in case of static
variables/methods. Keep this in mind and save your time when debugging.
best regards - michal
----
Manual Page -- http://www.php.net/manual/en/language.oop5.static.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51484
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51484&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51484&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51484&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51484&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51484&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51484&report=yes
Search -- http://master.php.net/manage/user-notes.php