3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait Singleton { public static function getInstance(){ static $counter = 0; static $instance = null; if (!isset($instance)) { echo 'new instance has been set'; $instance = new static(); } $counter++; echo "$counter\n"; return $instance; } } abstract class Abudabia { use Singleton; } class a1 extends Abudabia { public function set() { return 'allah ahbar'; } } class a2 extends Abudabia { public function get() { return 'algazira'; } } $a = a1::getInstance(); $b = a2::getInstance(); $a = a1::getInstance(); $b = a2::getInstance(); $a = a1::getInstance(); $b = a2::getInstance(); var_dump($a,$b);
based on JYXfU