Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么';当请求失败时php7捕获是否可丢弃?_Php_Php 7 - Fatal编程技术网

为什么';当请求失败时php7捕获是否可丢弃?

为什么';当请求失败时php7捕获是否可丢弃?,php,php-7,Php,Php 7,我试图捕获一个致命错误(): 但是,脚本在所有php版本中都会消失: Warning: require(foo): failed to open stream: No such file or directory in /in/5MV3I on line 4 Fatal error: require(): Failed opening required 'foo' (include_path='.:') in /in/5MV3I on line 4 Process exited with c

我试图捕获一个致命错误():

但是,脚本在所有php版本中都会消失:

Warning: require(foo): failed to open stream: No such file or directory in /in/5MV3I on line 4

Fatal error: require(): Failed opening required 'foo' (include_path='.:') in /in/5MV3I on line 4

Process exited with code 255.
医生说():

…除故障外,它还会产生致命的E_编译错误级别错误

哪些类型的php7致命错误是可捕获的,哪些是不可捕获的?

如果使用“require()”包含文件。你需要它。如果它不存在,则以编译错误结束。PHP然后中止。其思想是,在关键文件上使用require。如果这些数据丢失,它将立即中止

如果你想抓住一些东西,你必须选择“include()”。在这里,您可以轻松获得成功:

$includeResult = include("foo");
if (!$includeResult) {
    // you will land here, if include did not work.
}

根据定义,致命错误是不可恢复的。它们是不可捕获的。如果您想要更优雅的失败,可以使用
include()
。那些甚至会阻止代码被解析的错误将无法捕获,因为解析是在代码运行之前发生的。这就是为什么require-one不是:这发生在PHP仍在组装代码时,以及在它尝试运行任何代码之前。我找不到任何描述这两种类型错误(即编译和运行时)分离的文档。@Sammitch imho这个一般性语句对于php7来说是完全错误的。至少php文档不清楚什么是“致命”错误,它不存在于错误类层次结构中。另一方面,致命意味着致命——只有那些是致命的没有文档。Imho adam揭示了这个特定错误案例的原因。我们可以这样想:你可以从致命错误中恢复程序,就像你可以从致命伤害中恢复一样简单。原谅我,我已经把这个问题说得更清楚了。@andig好吧,这并没有记录得那么好。但几乎每一个致命错误都是不可捕捉的。可能错误文档对您有更多帮助:
$includeResult = include("foo");
if (!$includeResult) {
    // you will land here, if include did not work.
}