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) { return static::getFunction($v, function($value) { return $value == 1 || $value == true; }); } public static function parseNewLines($v) { return static::getFunction($v, function($value) { return trim(preg_replace('/\s\s+/', ' ', $string)); }); } } echo LazyLoadedMethods::toBool(-1);
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Non-static method LazyLoadedMethods::get() cannot be called statically in /in/FTLvd:30 Stack trace: #0 /in/FTLvd(37): LazyLoadedMethods::getFunction(-1, Object(Closure)) #1 /in/FTLvd(46): LazyLoadedMethods::toBool(-1) #2 {main} thrown in /in/FTLvd on line 30
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.18 ms | 401 KiB | 8 Q