3v4l.org

run code in 300+ PHP versions simultaneously
<?php class LazyLoadedMethods { protected $_data = array(); protected static $_instance; protected static function set($key, $value){ static::$_instance->_data[$key] = $value; return static::$_instance; } protected static 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(__FUNCTION__, function($value) { return trim(preg_replace('/\s\s+/', ' ', $string)); }); return $fn($v); } } var_dump(LazyLoadedMethods::toBool(-1)); var_dump(LazyLoadedMethods::parseNewLines("Some\n new\n lines\n"));
Output for git.master, git.master_jit, rfc.property-hooks
bool(true) Warning: Undefined variable $string in /in/H7gMd on line 42 Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /in/H7gMd on line 42 string(0) ""

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:
39.76 ms | 401 KiB | 8 Q