register_shutdown_function() 和 set_error_handler() 可以捕获相同的错误吗?

pro*_*het 2 php error-handling

如果我在同一个脚本中定义了以下内容:

register_shutdown_function('handlerOne');
set_error_handler('handlerTwo');
Run Code Online (Sandbox Code Playgroud)

是否有任何错误类型会触发两个处理程序?

Acc*_*t م 5

关断功能,当脚本执行完毕是否有错误,异常或不被执行。它与错误或异常无关,错误或异常不会触发它,也不会捕获它们,无论如何都会在脚本末尾调用它,因此如果您甚至想做一些工作,这很有用如果发生异常或致命错误,因为如果发生致命错误或异常,则不会执行错误处理程序函数。

错误处理功能被触发错误时将被执行。这是从手册中引用的

用户定义的函数无法处理以下错误类型:E_ERROR、E_PARSE、E_CORE_ERROR、E_CORE_WARNING、E_COMPILE_ERROR、E_COMPILE_WARNING,以及在调用 set_error_handler() 的文件中引发的大部分 E_STRICT。

<?php

function shutdownFunction(){
    echo "shutdownFunction is called \n";
} 

function errorHandlerFunction(){
    echo "errorHandlerFunction is called \n";
} 
register_shutdown_function('shutdownFunction');
set_error_handler('errorHandlerFunction');

//echo "foo\n"; // scenario 1 no errors
//echo $undefinedVar; //scenario 2 error is triggered
//undefinedFunction(); //scenario 3 Fatal error is triggered
//throw new \Exception(); //scenario 4 exception is thrown
Run Code Online (Sandbox Code Playgroud)

场景 1(无错误)输出

foo 
shutdownFunction is called
Run Code Online (Sandbox Code Playgroud)

场景 2(触发错误)输出

errorHandlerFunction is called 
shutdownFunction is called 
Run Code Online (Sandbox Code Playgroud)

场景 3(触发致命错误)输出

Fatal error: Call to undefined function undefinedFunction() in /tmp/execpad-b2a446c7f6a6/source-b2a446c7f6a6 on line 15
shutdownFunction is called
Run Code Online (Sandbox Code Playgroud)

场景 4(抛出异常)输出

Fatal error: Uncaught exception 'Exception' in /tmp/execpad-0b3a18f0ea06/source-0b3a18f0ea06:16
Stack trace:
#0 {main}
thrown in /tmp/execpad-0b3a18f0ea06/source-0b3a18f0ea06 on line 16
shutdownFunction is called 
Run Code Online (Sandbox Code Playgroud)

自己看看https://eval.in/1073642