3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Singleton { protected static $instance; final public static function getInstance() { if (!isset(static::$instance)) { static::$instance = new static; } return static::$instance; } } class a1{ use Singleton; } class a2{ use Singleton; } $a = a1::getInstance(); $b = a2::getInstance(); $a = a1::getInstance(); $b = a2::getInstance(); var_dump($a,$b);

preferences:
29.34 ms | 402 KiB | 5 Q