exit()
exit() — Terminate the current script with a status code or message.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit() is called. However, finally blocks are never executed.
Signature
exit(string|int $status = 0): never
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $status | string|int | If status is an int, the exit code returned by PHP will be status. Note: Exit codes should be in the range 0 to 254, the exit code 255 is reserved by PHP and should not be used. |
Return value
As this terminates the PHP script, no value is returned.
Example
A runnable snippet:
// exit program normally exit(); exit(0); // exit with an error code exit(1);
Changelog
| Version | Change |
|---|---|
| 8.4.0 | exit() is now a proper function, therefore it follows the usual type juggling semantics is affected by the strict_types declare, can be called with named arguments, and be a variable functions. |
| 8.4.0 | A parameterless exit() called within shutdown functions or object destructors now resets the exit code to 0; previously the exit code set by an earlier exit() call was kept. |
See also
register_shutdown_function(), register_shutdown_function()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page exit() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.