3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class CallableStringifier { private static $callables = array(); public static function stringify($callable) { $id = count(self::$callables); self::$callables[$id] = $callable; return 'return ' . __CLASS__ . "::call($id, func_get_args());"; } public static function call($id, $args) { return call_user_func_array(self::$callables[$id], $args); } } $func = create_function('$arg1', CallableStringifier::stringify(function($arg1) { return $arg1; })); echo $func(function(){return 3;}); // outputs 1
based on ivMri
Output for 7.2.0
Deprecated: Function create_function() is deprecated in /in/qlA6f on line 22 Recoverable fatal error: Object of class Closure could not be converted to string in /in/qlA6f on line 24
Process exited with code 255.
Output for 7.1.0 - 7.1.10
Recoverable fatal error: Object of class Closure could not be converted to string in /in/qlA6f on line 24
Process exited with code 255.
Output for 5.3.17 - 7.0.20
Catchable fatal error: Object of class Closure could not be converted to string in /in/qlA6f on line 24
Process exited with code 255.