3v4l.org

run code in 300+ PHP versions simultaneously
<?php $success=false; if (true){ set_error_handler(function($a, $b, $c, $d) { var_dump('error_handler', $a, $b, $c, $d); }); register_shutdown_function(function(){ if ($success){return;} var_dump(get_last_error()); }); } $var = 1; try { $var->method(); // Throws an Error object in PHP 7. } catch (Error $e) { // Handle error var_dump('error', $e); } catch (Exception $e) { // Handle error var_dump('exception', $e); } $success=true; ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
string(5) "error" object(Error)#3 (7) { ["message":protected]=> string(41) "Call to a member function method() on int" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/Uh2AD" ["line":protected]=> int(17) ["trace":"Error":private]=> array(0) { } ["previous":"Error":private]=> NULL } string(13) "error_handler" int(2) string(27) "Undefined variable $success" string(9) "/in/Uh2AD" int(8) Fatal error: Uncaught Error: Call to undefined function get_last_error() in /in/Uh2AD:10 Stack trace: #0 [internal function]: {closure}() #1 {main} thrown in /in/Uh2AD on line 10
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
string(5) "error" object(Error)#3 (7) { ["message":protected]=> string(41) "Call to a member function method() on int" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/Uh2AD" ["line":protected]=> int(17) ["trace":"Error":private]=> array(0) { } ["previous":"Error":private]=> NULL } string(13) "error_handler" int(8) string(27) "Undefined variable: success" string(9) "/in/Uh2AD" int(8) Fatal error: Uncaught Error: Call to undefined function get_last_error() in /in/Uh2AD:10 Stack trace: #0 [internal function]: {closure}() #1 {main} thrown in /in/Uh2AD on line 10
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33
string(5) "error" object(Error)#3 (7) { ["message":protected]=> string(45) "Call to a member function method() on integer" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/Uh2AD" ["line":protected]=> int(17) ["trace":"Error":private]=> array(0) { } ["previous":"Error":private]=> NULL } string(13) "error_handler" int(8) string(27) "Undefined variable: success" string(9) "/in/Uh2AD" int(8) Fatal error: Uncaught Error: Call to undefined function get_last_error() in /in/Uh2AD:10 Stack trace: #0 [internal function]: {closure}() #1 {main} thrown in /in/Uh2AD on line 10
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Fatal error: Call to a member function method() on integer in /in/Uh2AD on line 17 string(13) "error_handler" int(8) string(27) "Undefined variable: success" string(9) "/in/Uh2AD" int(8) Fatal error: Call to undefined function get_last_error() in /in/Uh2AD on line 10
Process exited with code 255.
Output for 5.5.24 - 5.5.35
Fatal error: Call to a member function method() on a non-object in /in/Uh2AD on line 17 string(13) "error_handler" int(8) string(27) "Undefined variable: success" string(9) "/in/Uh2AD" int(8) Fatal error: Call to undefined function get_last_error() in /in/Uh2AD on line 10
Process exited with code 255.

preferences:
162.93 ms | 401 KiB | 193 Q