3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
69.09 ms | 402 KiB | 5 Q