我对 C、C++ 或比 PHP 更低的级别一无所知。我看了一下 github 上的 Codeigniter 3 代码,发现它添加了 exit status code constants ,即我们可以这样做:
exit(EXIT_DATABASE)
表示 exit(8)
或 exit(EXIT_UNKNOWN_CLASS)
表示 exit(5)
有什么区别
echo 'Configuration file not found';
exit(3);
只是
exit('找不到配置文件');
?
在 php 中使用 exit(integer)
的目的是什么?它不打印任何东西,是吗?我也检查了 the docs和谷歌一些但仍然不清楚。 如何使用它?我可以从哪里获得这方面的引用?
谢谢。
最佳答案
它向调用者提示运行脚本的结果。
如果您使用 exec
或 system
运行脚本并且您需要根据运行脚本的结果采取不同的行为,这在 php 中可能很有用。
<?php
$output = array();
$error = null;
exec("/path/to/php cleanData.php", $output, $error);
if ($error){
Logger::log($error, $output);
die("Sorry I was Unable to Clean the Data\n");
}
关于php - 什么是 Exit(integer) 以及如何在 PHP 中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16986524/