3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test1() { // We have to check for existance because each call will try to define the function globally like including a file would. if (!function_exists('test2')) { function test2() { echo 'there' . PHP_EOL; } } echo 'here' . PHP_EOL; } echo "The internal method isn't defined yet: "; var_dump(function_exists('test2')); test1(); echo "Woops, function definitions don't get scoped by the function that define them. That's a feature but now we accidentally have a global function we might not have intended!: "; var_dump(function_exists('test2')); test2();
Output for 5.5.18, 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
The internal method isn't defined yet: bool(false) here Woops, function definitions don't get scoped by the function that define them. That's a feature but now we accidentally have a global function we might not have intended!: bool(true) there

preferences:
58.82 ms | 407 KiB | 5 Q