php exit 后执行,在php中使用exit(0)的方法声明退出状态(成功退出还是由于某情况意外终止),这样做有什么好处?这与直接退出有什么区别...

先给出结论: 有细微区别。

讲道理还是拿文档说事:

If status is a string, this function prints the status just before exiting.

If status is an integer, that value will be used as the exit status and not printed. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.

Note: PHP >= 4.2.0 does NOT print the status if it is an integer.

简单点说就是: 如果是字符串,就会打印出来,如果是数字,就会作为退出的状态码,不会被打印。

echo "出错"; exit(3);

// exit("出错");

?>

分别执行上面两行代码,很显然可以看出结果是一样的。

区别在于:

注释第二行,在终端执行下面命令:

php test.php // 打印"出错"

echo $? //打印 3

注释第一行,在终端执行下面命令:

php test.php // 打印"出错"

echo $? //打印 0

也就是说,eixt()当参数为int类型的时候,会作为退出状态码。

$?解释:Stores the exit value of the last command that was executed(最后一条命令的退出状态,0表示没有错误).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值