in PHP Does die()
gives anything in return when we use it?
In PHP the function die() just quit running the script and prints out the argument (if there's any).
http://php.net/die
Obviously, die()
or its equivalent exit()
don't return anything to the script itself; to be precise, this code doesn't make much sense:
if (die())) {
echo 'are we dead yet?';
}
However, depending on what you pass as the (optional) argument of die()
or exit()
, it does return something to the caller, i.e. the command that caused your script to run. Its practical use is usually limited to the cli
SAPI though, when you call the script from a command line using php /path/to/script.php
.
Observe:
die('goodbye cruel world');
This code would print goodbye cruel world
and then return an exit status code of 0
, signalling to the caller that the process terminated normally.
Another example:
die(1);
When you pass an integer value instead of a string, nothing is printed and the exit status code will be 1
, signalling to the caller that the process didn't terminate normally.
Lastly, die()
without any arguments is the same as die(0)
.
The exit status of a process can be changed to signal different kinds of errors that may have occurred, e.g. 1
means general error, 2
means invalid username, etc.
It is the same as exit() and according to documentation it returns nothing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With