PHP die() 返回什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/892222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what does PHP die() return
提问by developer
in PHP Does die()gives anything in return when we use it?
在 PHP 中die(),当我们使用它时会给予任何回报吗?
回答by Ivar
In PHP the function die() just quit running the script and prints out the argument (if there's any).
在 PHP 中,函数 die() 只是停止运行脚本并打印出参数(如果有的话)。
回答by soulmerge
回答by Ja?ck
Obviously, die()or its equivalent exit()don't return anything to the script itself; to be precise, this code doesn't make much sense:
显然,die()或者它的等价物exit()不会向脚本本身返回任何内容;准确地说,这段代码没有多大意义:
if (die())) {
echo 'are we dead yet?';
}
However, depending on what you pass as the (optional) argument of die()or exit(), it doesreturn something to the caller, i.e. the command that caused your script to run. Its practical use is usually limited to the cliSAPI though, when you call the script from a command line using php /path/to/script.php.
但是,根据您作为die()or的(可选)参数传递的内容exit(),它确实会向调用者返回一些内容,即导致您的脚本运行的命令。但它的实际用途通常仅限于cliSAPI,当您使用php /path/to/script.php.
Observe:
观察:
die('goodbye cruel world');
This code would print goodbye cruel worldand then return an exit status codeof 0, signalling to the caller that the process terminated normally.
该代码将打印goodbye cruel world,然后返回一个退出状态代码的0,信令给调用者,该方法正常终止。
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.
当您传递整数值而不是字符串时,不会打印任何内容,退出状态代码将为1,向调用者发出信号,表明进程未正常终止。
Lastly, die()without any arguments is the same as die(0).
最后,die()没有任何参数与die(0).
The exit status of a process can be changed to signal different kinds of errors that may have occurred, e.g. 1means general error, 2means invalid username, etc.
可以更改进程的退出状态以指示可能发生的不同类型的错误,例如1表示一般错误,2表示无效的用户名等。
回答by victor hugo
It is the same as exit()and according to documentation it returns nothing
它与 exit() 相同,根据文档,它不返回任何内容
回答by Jet
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.
没有理由在 die/exit 中返回一些东西。此函数终止内部的 php 解释器进程并将退出代码返回给 shell。所以在调用 die() 之后,就没有执行脚本的解释器进程而言,没有脚本执行,这就是为什么没有办法处理函数的返回。
回答by Rik Heywood
It does not return. The script is terminated and nothing else is executed.
它不会返回。脚本终止,没有执行任何其他操作。

