3v4l.org

run code in 300+ PHP versions simultaneously
<?php class LazyLoadedMethods { protected $_data = array(); protected static $_instance; protected function set($key, $value){ static::$_instance->_data[$key] = $value; return static::$_instance; } protected function get($key){ if(array_key_exists($key, static::$_instance->_data)){ return static::$_instance->_data[$key]; } return null; } public static function getInstance() { if (!isset(static::$_instance)) { static::$_instance = new static; } return static::$_instance; } protected static function getFunction($name, $callback){ $ins = static::getInstance(); if(is_null(static::get($name))){ static::set($name, $callback); } return static::get($name); } public static function toBool($v) { $fn = static::getFunction(__FUNCTION__, function($value) { return $value == 1 || $value == true; }); return $fn($v); } public static function parseNewLines($v) { $fn = static::getFunction($v, function($value) { return trim(preg_replace('/\s\s+/', ' ', $string)); }); return $fn($v); } } var_dump(LazyLoadedMethods::toBool(-1));
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.6
Fatal error: Uncaught Error: Non-static method LazyLoadedMethods::get() cannot be called statically in /in/t4NcG:30 Stack trace: #0 /in/t4NcG(37): LazyLoadedMethods::getFunction('toBool', Object(Closure)) #1 /in/t4NcG(48): LazyLoadedMethods::toBool(-1) #2 {main} thrown in /in/t4NcG on line 30
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: Non-static method LazyLoadedMethods::get() should not be called statically in /in/t4NcG on line 30 Deprecated: Non-static method LazyLoadedMethods::set() should not be called statically in /in/t4NcG on line 31 Deprecated: Non-static method LazyLoadedMethods::get() should not be called statically in /in/t4NcG on line 33 bool(true)
Output for 7.3.32 - 7.3.33
bool(true)
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
Strict Standards: Non-static method LazyLoadedMethods::get() should not be called statically in /in/t4NcG on line 30 Strict Standards: Non-static method LazyLoadedMethods::set() should not be called statically in /in/t4NcG on line 31 Strict Standards: Non-static method LazyLoadedMethods::get() should not be called statically in /in/t4NcG on line 33 bool(true)
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting T_VARIABLE in /in/t4NcG on line 8
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting T_VARIABLE in /in/t4NcG on line 8
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/t4NcG 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/t4NcG 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/t4NcG on line 4
Process exited with code 255.

preferences:
299.69 ms | 401 KiB | 423 Q