3v4l.org

run code in 300+ PHP versions simultaneously
<?php class LazyLoadedMethods { protected $_data = array(); 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);

preferences:
56.33 ms | 402 KiB | 5 Q