3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait Singleton { private static $instance; private function __construct() {} private function __clone() {} private function __wakeup() {} public function getInstance() { if (empty(static::$instanse)) { return new static(); } else { return static::$instance; } } } class Foo { use Singleton; private $bar = 2; public function incBar() { $this->bar++; } public function getBar() { return $this->bar."<br/>"; } } $foo = Foo::getInstance(); echo $foo->getBar(); $foo->incBar(); echo $foo->getBar();
based on Y0p7Z
Output for 7.0.0 - 7.2.0
Deprecated: Non-static method Foo::getInstance() should not be called statically in /in/AJmhE on line 38 2<br/>3<br/>
Output for 5.4.9 - 5.6.28
Strict Standards: Non-static method Foo::getInstance() should not be called statically in /in/AJmhE on line 38 2<br/>3<br/>
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/AJmhE on line 3
Process exited with code 255.