3v4l.org

run code in 300+ PHP versions simultaneously
<?php class hell { private $ruler = 'devil'; function cry(){ echo $this->ruler; } } $inst = new hell(); $inst->cry(); $in2 = Closure::bind(function () {$this->ruler = 'jesus';}, $inst, get_class($inst)); $in2(); $inst->cry(); class Singleton { protected static $instance; // object instance private function __construct(){ /* ... @return Singleton */ } // Защищаем от создания через new Singleton private function __clone() { /* ... @return Singleton */ } // Защищаем от создания через клонирование private function __wakeup() { /* ... @return Singleton */ } // Защищаем от создания через unserialize public static function getInstance() { // Возвращает единственный экземпляр класса. @return Singleton if ( !isset(self::$instance) ) { $class = __CLASS__; self::$instance = new $class(); selt::$instance->id = mt_rand(1,1000); } return self::$instance; } public function doAction() { echo $this->id; } } Singleton::getInstance()->doAction(); // Применение $singy = Singleton::getInstance();
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.7, 7.2.0
deviljesus Fatal error: Uncaught Error: Class 'selt' not found in /in/eXOKI:28 Stack trace: #0 /in/eXOKI(34): Singleton::getInstance() #1 {main} thrown in /in/eXOKI on line 28
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
deviljesus Fatal error: Class 'selt' not found in /in/eXOKI on line 28
Process exited with code 255.
Output for 5.3.0 - 5.3.29
devil Fatal error: Call to undefined method Closure::bind() in /in/eXOKI on line 15
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/eXOKI on line 15
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/eXOKI on line 15
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/eXOKI on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/eXOKI on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/eXOKI on line 4
Process exited with code 255.

preferences:
186.57 ms | 401 KiB | 216 Q