3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected $b = null; protected static $instance = null; public static function get() { if (static::$instance === null) { static::$instance = new static(); } return static::$instance; } public function __construct() { echo __METHOD__ . PHP_EOL; $this->b = Bar::get(); } public function __destruct() { echo __METHOD__ . PHP_EOL; $this->b->func(); } } class Bar { public $destroyed = false; protected static $instance = null; public static function get() { if (static::$instance === null) { static::$instance = new static(); } return static::$instance; } public function __construct() { echo __METHOD__ . PHP_EOL; } public function __destruct() { echo __METHOD__ . PHP_EOL; $this->destroyed = true; } public function func() { echo __METHOD__ . PHP_EOL; } } Bar::get(); Foo::get();
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.27, 8.0.0 - 8.0.15, 8.1.0 - 8.1.2
Bar::__construct Foo::__construct Bar::__destruct Foo::__destruct Bar::func

preferences:
58.27 ms | 529 KiB | 12 Q