The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script.
The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called.
The message to be displayed is passed as a parameter to the exit() function and it terminates the script and displays the message.
The exit() function is an alias of the die() function.
The exit() function in PHP accepts one parameter.
- message : It is a mandatory parameter which specifies the message or status number to write before exiting the script.
Return Value: It does not return any value.
Errors And Exceptions
- exit() is a language construct and it can be called without parentheses if no status is passed.
- If the status passed as a parameter is an integer, that value will be used as the exit status and not be printed.
- Exit statuses should be in the range 0 to 254 and the exit status 255 should not be used since it is reserved by PHP.
Below programs illustrate the exit() function:
Unable to establish a connection to https://www.geeksforgeeks.org
variables are equal
- How to get the function name inside a function in PHP ?
- PHP | max( ) Function
- p5.js | arc() Function
- D3.js | d3.map.set() Function
- D3.js | d3.set.has() Function
- PHP | min( ) Function
- CSS | hsl() Function
- PHP | end() Function
- PHP | pos() Function
- D3.js | d3.hsl() Function
- PHP | Ds\Set contains() Function
- PHP | next() Function
- PHP | key() Function
- CSS | var() Function
- p5.js | mag() Function
- PHP | Ds\Map map() Function
- PHP | Ds\Map last() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.