3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class FooSingleton extends BarSingleton { private $foo_instance; public static function getInstance() { if (!self::$foo_instance) { self::$foo_instance = new self; } } } class BarSingleton { private $bar_instance; public static function getInstance() { if (!self::$bar_instance) { // Defer to FooSingleton self::$bar_instance = parent::getInstance(); } } } $foo = FooSingleton::getInstance(); $bar = BarSingleton::getInstance(); // This should be true var_dump($foo === $bar);
based on aOUpn
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Access to undeclared static property: FooSingleton::$foo_instance in /in/K2M1J:10 Stack trace: #0 /in/K2M1J(34): FooSingleton::getInstance() #1 {main} thrown in /in/K2M1J on line 10
Process exited with code 255.
Output for 5.3.21 - 5.6.28
Fatal error: Access to undeclared static property: FooSingleton::$foo_instance in /in/K2M1J on line 10
Process exited with code 255.