从PHP 5到PHP 7,语法错误不再是致命错误,而是可以捕获的Throwable
异常。但是,在PHP 7中,一些致命错误(如“未找到类”)仍然致命。为什么并非所有致命错误都转换为Throwable
?
示例:
try {
include "file_with_syntax_error.php";
} catch (Throwable $ex) {
// Do something
}
但是
try {
include "file_with_namespace_error.php";
} catch (Throwable $ex) {
// Won't work
}
修改:错误报告https://bugs.php.net/bug.php?id=72089中有评论:
一般来说,这已经在PHP 7.0.0中完成了 合理的,可能的,见 https://wiki.php.net/rfc/engine_exceptions_for_php7