3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Aareon_Abstract { public static $instance; public static function getInstance() { if (self::$instance === null) { self::$instance = new static(); } return self::$instance; } } class Aareon_MaterializedView extends Aareon_Abstract { public static $instance; } class Sample extends Aareon_Abstract { } echo get_class(Aareon_Abstract::getInstance()) . PHP_EOL; echo get_class(Aareon_MaterializedView::getInstance()) . PHP_EOL; //As you can see, a new B is instantiated here, because B::$instance is a priority over A::$instance. echo get_class(Aareon_Abstract::getInstance()) . PHP_EOL; A::$instance = null; echo PHP_EOL; echo get_class(Aareon_Abstract::getInstance()) . PHP_EOL; echo get_class(Sample::getInstance()) . PHP_EOL; //But here, there is no C::$instance, so let's check the A::$instance which is not empty. echo get_class(Aareon_Abstract::getInstance()) . PHP_EOL;
based on sGQGS
Output for 7.0.0 - 7.2.0
Aareon_Abstract Aareon_Abstract Aareon_Abstract Fatal error: Uncaught Error: Class 'A' not found in /in/HfZlr:28 Stack trace: #0 {main} thrown in /in/HfZlr on line 28
Process exited with code 255.
Output for 5.3.18 - 5.6.28
Aareon_Abstract Aareon_Abstract Aareon_Abstract Fatal error: Class 'A' not found in /in/HfZlr on line 28
Process exited with code 255.