文章目录
die()和exit()函数在PHP中有什么区别?
我认为两者都具有相同的功能,但是我怀疑这两者有什么不同…这是什么?
没有区别 - 他们是一样的。
PHP手册exit:Note: This language construct is equivalent to
die().
PHP手册die:This language construct is equivalent to
exit().
PHP中die()和exit()的区别是它们的起源。
exit()从exit()在C. die()来自Perl中的die。
FUNCTIONALLY EQUIVALENT
die()和exit()是等效的功能。
PHP Manual
PHP手册die:This language construct is equivalent to
exit().
PHP手册exit:Note: This language construct is equivalent to
die().
函数别名列表的PHP手册:die is an alias for master
function exit()
DIFFERENT IN OTHER LANGUAGES
die()和exit()在其他语言是不同的,但在PHP中它们是相同的。
从另一个PHP的咆哮:…As a C and Perl coder, I was ready to answer, “Why, exit() just bails off
the program with a numeric exit status, while die() prints out the error
message to stderr and exits with EXIT_FAILURE status.” But then I remembered
we’re in messy-syntax-land of PHP.
>In PHP, exit() and die() are identical.
>The designers obviously thought “Hmm, let’s borrow exit() from
C. And Perl folks probably will
like it if we take die() as is from
Perl too. Oops! We have two exit
functions now! Let’s make it so that they both can take a string or integer as
an argument and make them identical!”
>The end result is that this didn’t really make things any “easier”, just
more confusing. C and Perl coders will continue to use exit() to toss an
integer exit value only, and die() to toss an error message and exit with a
failure. Newbies and PHP-as-a-first-language people will probably wonder “umm,
two exit functions, which one should I use?” The manual doesn’t explain why
there’s exit() and die().
>In general, PHP has a lot of weird redundancy like this - it tries to be
friendly to people who come from different language backgrounds, but while
doing so, it creates confusing redundancy.
未经作者同意,本文严禁转载,违者必究!