in PHP Does die()
gives anything in return when we use it?

- 307,395
- 66
- 306
- 293

- 2,042
- 10
- 40
- 59
-
4it returns nothing. But even if it returns something, that something still can't be used for nothing, since the script is quitting. – andyk May 21 '09 at 10:49
5 Answers
In PHP the function die() just quit running the script and prints out the argument (if there's any).

- 147,647
- 23
- 218
- 272

- 4,344
- 6
- 38
- 53
-
9This is not quite accurate. If die() is called with an integer argument, it returns that value. In a web context, this may not mean much. In a CLI PHP script, that return value is meaningful; it's available for use in the shell. – Alexander Garden May 31 '12 at 13:10
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.

- 170,779
- 38
- 263
- 309
It is the same as exit() and according to documentation it returns nothing

- 35,514
- 12
- 68
- 79
It does not return. The script is terminated and nothing else is executed.

- 13,816
- 9
- 61
- 81
-
It prints the given message before terminating. https://www.w3schools.com/PHP/func_misc_die.asp – SherylHohman Mar 23 '20 at 00:18
There's no reason to return something in die/exit. This function terminates php interpreter process inside and returns exit-code to shell. So after calling die() there is no script execution as far as there is no interpreter process which executes the script and that's why there is no way to handle function's return.

- 1,171
- 6
- 8
-
It prints $message before terminating the process. https://www.w3schools.com/PHP/func_misc_die.asp – SherylHohman Mar 23 '20 at 00:17