php 出口(); 死(); 返回假;

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8490731/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:51:38  来源:igfitidea点击:

exit(); die(); return false;

php

提问by daryl

Possible Duplicate:
what are the differences in die() and exit() in PHP?

可能的重复:
PHP 中的 die() 和 exit() 有什么区别?

I guess the main question is what is the difference between the 3 exactly?

我想主要问题是 3 之间到底有什么区别?

What is the correct semantic usage for each one of these?

每一个的正确语义用法是什么?

From what I see return false;can discontinue a function whereas die();and exit();will prevent any further code running at all.

从我看到return false;可以停止,而功能die();exit();防止运行任何进一步的代码在所有

Is this correct?

这样对吗?

回答by Ernest Friedman-Hill

die()and exit()are precisely identical; they halt the entire PHP program and return to the OS. They're two different names for the same function.

die()并且exit()完全相同;他们停止整个 PHP 程序并返回到操作系统。它们是同一功能的两个不同名称。

return, on the other hand, ends a function call and returns to the caller. At the end of a program, returnsets the status value that is returned to the OS; the program is going to exit no matter what.

return,另一方面,结束函数调用并返回给调用者。在程序结束时,return设置返回给操作系统的状态值;无论如何,程序都会退出。

回答by daryl

According to docs PHP: exit Manualdie()is an alias to exit()so they do the same function and that is to END the script.

根据文档PHP: exit Manualdie()是一个别名,exit()因此它们执行相同的功能,即结束脚本。

The returnstatement ends a function and not the entire script, and returns the value that you choose.

return语句结束一个函数而不是整个脚本,并返回您选择的值。