简体   繁体   中英

what does PHP die() return

在PHP中,当我们使用它时, die()会给出任何回报吗?

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, ie 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, eg 1 means general error, 2 means invalid username, etc.

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

它与exit()相同 ,根据文档,它不返回任何内容

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM