note 50645 added to language.oop5.paamayim-nekudotayim

From: Date: Sat, 05 Mar 2005 17:43:33 +0000
Subject: note 50645 added to language.oop5.paamayim-nekudotayim
Groups: php.notes 
Request: Send a blank email to php-notes+get-85976@lists.php.net to get a copy of this message
There is also a quirk with using the scope resolution operator on static class variables. Below is an example using a highly modified version of Ian's code: <?php class ExampleSuperclass { static $className; static function showClassName() { echo self::$className . "\n"; } } class ExampleSubclassOne extends ExampleSuperclass { static function setClassName() { self::$className = "subclassOne"; } } class ExampleSubclassTwo extends ExampleSuperClass { static function setClassName() { self::$className = "subclassTwo"; } } // setting variables for each class ExampleSubclassOne::setClassName(); ExampleSubclassTwo::setClassName(); ExampleSubclassOne::showClassName(); // output is "subclassTwo"! // more output: echo ExampleSubclassOne::$className . "\n"; // output is "subclassTwo"! echo ExampleSubclassTwo::$className . "\n"; // output is "subclassTwo" echo ExampleSuperclass::$className . "\n"; // output is "subclassTwo"! ?> appearantly, any static variables defined in a superclass are directly referenced in subclasses, and all changes are visible throughout the class heirarchy. care must be taken when using static class variables. ---- Manual Page -- http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50645 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50645&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50645&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50645&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50645&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50645&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50645&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85976) next »