|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-04-15 03:01 UTC] laruence@php.net
-Status: Open
+Status: Not a bug
[2013-04-15 03:01 UTC] laruence@php.net
[2013-04-15 06:28 UTC] pretzlaw at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 04:00:02 2025 UTC |
Description: ------------ Inherit a class with a static method. The static method has static variable in it. Now execute both methods and watch the variable. It wont change from one class to another. Test script: --------------- <?php class A { function __construct() { echo get_class($this->getInstance()), PHP_EOL, get_class(static::getInstance()), PHP_EOL, get_class(self::getInstance()), PHP_EOL; } public static function getInstance() { static $getInstance; if (null == $getInstance) $getInstance = self::makeInstance(); return $getInstance; } public static function makeInstance() { return new stdClass(); } } $a = new A(); class B extends A { function __construct() { echo get_class($this->getInstance()), PHP_EOL, get_class(static::getInstance()), PHP_EOL, get_class(self::getInstance()), PHP_EOL; } public static function makeInstance() { return new ArrayObject(); } } $a = new B(); Expected result: ---------------- stdClass stdClass stdClass ArrayObject ArrayObject stdClass Actual result: -------------- stdClass stdClass stdClass stdClass stdClass stdClass