[ACCEPTED]-what does PHP die() return-die

Accepted answer
Score: 28

In PHP the function die() just quit running 2 the script and prints out the argument (if 1 there's any).

http://php.net/die

Score: 12

Obviously, die() or its equivalent exit() don't return 19 anything to the script itself; to be precise, this 18 code doesn't make much sense:

if (die())) {
    echo 'are we dead yet?';
}

However, depending 17 on what you pass as the (optional) argument 16 of die() or exit(), it does return something to the caller, i.e. the 15 command that caused your script to run. Its 14 practical use is usually limited to the 13 cli SAPI though, when you call the script from 12 a command line using php /path/to/script.php.

Observe:

die('goodbye cruel world');

This code 11 would print goodbye cruel world and then return an exit status code of 0, signalling 10 to the caller that the process terminated 9 normally.

Another example:

die(1);

When you pass an 8 integer value instead of a string, nothing 7 is printed and the exit status code will 6 be 1, signalling to the caller that the process 5 didn't terminate normally.

Lastly, die() without 4 any arguments is the same as die(0).

The exit status 3 of a process can be changed to signal different 2 kinds of errors that may have occurred, e.g. 1 means 1 general error, 2 means invalid username, etc.

Score: 11

Why don't you have a look at the wonderful 2 documentation of PHP? It even contains information 1 about die()

Score: 3

It is the same as exit() and according to documentation it returns nothing

0

Score: 2

It does not return. The script is terminated 1 and nothing else is executed.

Score: 1

There's no reason to return something in 7 die/exit. This function terminates php interpreter 6 process inside and returns exit-code to 5 shell. So after calling die() there is no 4 script execution as far as there is no interpreter 3 process which executes the script and that's 2 why there is no way to handle function's 1 return.

More Related questions