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