3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ExitHandler { private static $exitCode = 0; private static $exitHandlers = []; private static $shutdownRegistered = false; public static function onExit(callable $callback, ...$args) { self::$exitHandlers[] = [$callback, $args]; if (!self::$shutdownRegistered) { register_shutdown_function(function() { foreach (self::$exitHandlers as list($handler, $args)) { $handler(self::$exitCode, ...$args); } }); self::$shutdownRegistered = true; } } public static function exit(int $code) { self::$exitCode = $code; exit($code); } } ExitHandler::onExit(function($code) { var_dump($code); }); ExitHandler::exit(123);
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 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.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
int(123)
Process exited with code 123.
Output for 5.6.0 - 5.6.38
Parse error: syntax error, unexpected 'exit' (T_EXIT), expecting identifier (T_STRING) in /in/bkDTW on line 26
Process exited with code 255.
Output for 5.5.0 - 5.5.38
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/bkDTW on line 11
Process exited with code 255.

preferences:
98.91 ms | 1956 KiB | 4 Q