3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * driver.php * ---------- * Registers a shutdown-function, that includes "error_handler.php" (which merely defines * a innocuous function named "handle_error", and includes "throw_fatal_error.php" * (that provokes an error declaring two classes with the same name). * * What happens is that the fatal error is thrown, shutdownFunc() is called and * "error_handler.php" is included -- but it occurs another fatal error, complaining that * handle_error() (defined in "error_handler.php") is undefined. * The problem does not happen with classes, as can be demonstrated by ErrorClass, * which is defined in "error_handler.php" and it's existence checked on shutdownFunc(). * * VERY IMPORTANT NOTE * If "throw_fatal_error.php" does not include a namespace or if neither class inherits * from another, everything works ok! */ function shutdownFunc () { eval(<<<'PHP' function handle_error () { echo "handle_error() is here<br />\n"; } class ErrorClass extends \stdclass {} PHP ); echo "We're about to call <em>handle_error()</em>...<br />\n"; echo 'ErrorClass is ', class_exists ('ErrorClass') ? 'undefined' : 'defined', "<br />\n"; handle_error(); } register_shutdown_function ('shutdownFunc'); // Make sure errors are printed. ini_set ('display_errors', 'On'); // Include the file that provokes the error. eval(<<<'PHP' namespace test; class aclass {} class aclass extends \stdclass {} PHP );
Output for 7.0.18 - 7.0.33, 7.1.4 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 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: Cannot declare class test\aclass, because the name is already in use in /in/EsDVZ(40) : eval()'d code on line 5 We're about to call <em>handle_error()</em>...<br /> ErrorClass is undefined<br /> handle_error() is here<br />
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: Cannot declare class test\aclass, because the name is already in use in /in/EsDVZ(40) : eval()'d code on line 5 We're about to call <em>handle_error()</em>...<br /> ErrorClass is undefined<br /> handle_error() is here<br />
Process exited with code 255.
Output for 7.0.0 - 7.0.17, 7.1.0 - 7.1.3
Fatal error: Cannot declare class test\aclass, because the name is already in use in /in/EsDVZ(44) : eval()'d code on line 5 We're about to call <em>handle_error()</em>...<br /> ErrorClass is undefined<br /> handle_error() is here<br />
Process exited with code 255.
Output for 5.6.0 - 5.6.40
Fatal error: Cannot redeclare class test\aclass in /in/EsDVZ(46) : eval()'d code on line 5 We're about to call <em>handle_error()</em>...<br /> ErrorClass is defined<br /> Fatal error: Call to undefined function handle_error() in /in/EsDVZ on line 31
Process exited with code 255.

preferences:
229.3 ms | 401 KiB | 291 Q