3v4l.org

run code in 300+ PHP versions simultaneously
<?php $args = '$user, $number'; $body = 'echo "#$number: Hello $user.\n";'; function _create_function_without_eval($args, $body) { $func_name = sprintf('temp_func_%s', md5($body)); $code = sprintf("<?php if (!function_exists('%s')) {function %s(%s){%s}}", $func_name, $func_name, $args, $body); $func_file = tempnam('/tmp', $func_name); $handle = fopen($func_file, "w+"); fwrite($handle, $code); fclose($handle); include $func_file; unlink($func_file); return function(...$user_args) use ($func_name) { return call_user_func_array($func_name, $user_args); }; } function _create_function_with_eval($args, $body) { $func_name = sprintf('temp_func_%s', md5($body)); $code = sprintf("if (!function_exists('%s')) {function %s(%s){%s}}", $func_name, $func_name, $args, $body); eval($code); return function(...$user_args) use ($func_name) { return call_user_func_array($func_name, $user_args); }; } $fn_deprecated = create_function($args, $body); $fn_with_eval = _create_function_with_eval($args, $body); $fn_without_eval = _create_function_without_eval($args, $body); echo $fn_deprecated('Old Bob', '1'); echo $fn_without_eval('Bob without eval', 2); echo $fn_with_eval('Bob with eval', 3);
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.4, 8.3.6
Fatal error: Uncaught Error: Call to undefined function create_function() in /in/urQ4k:29 Stack trace: #0 {main} thrown in /in/urQ4k on line 29
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught Error: Call to undefined function create_function() in /in/urQ4k:29 Stack trace: #0 {main} thrown in /in/urQ4k on line 29
Process exited with code 255.
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: Function create_function() is deprecated in /in/urQ4k on line 29 #1: Hello Old Bob. #2: Hello Bob without eval. #3: Hello Bob with eval.
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.3.32 - 7.3.33
#1: Hello Old Bob. #2: Hello Bob without eval. #3: Hello Bob with eval.

preferences:
223.46 ms | 402 KiB | 300 Q