3v4l.org

run code in 300+ PHP versions simultaneously
<?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();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Warning: The magic method Singleton::__wakeup() must have public visibility in /in/AJmhE on line 9 Fatal error: Uncaught Error: Non-static method Foo::getInstance() cannot be called statically in /in/AJmhE:38 Stack trace: #0 {main} thrown in /in/AJmhE on line 38
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: Non-static method Foo::getInstance() should not be called statically in /in/AJmhE on line 38 2<br/>3<br/>
Output for 7.3.32 - 7.3.33
2<br/>3<br/>
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Strict Standards: Non-static method Foo::getInstance() should not be called statically in /in/AJmhE on line 38 2<br/>3<br/>

preferences:
208.15 ms | 402 KiB | 331 Q