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(); $c = a1::getInstance(); $d = a2::getInstance(); var_dump($a,$b,$c,$d);

preferences:
36.16 ms | 402 KiB | 5 Q