Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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
尝试在PHP中使用全局异常处理程序以统一的方式处理各种顶级异常 请考虑以下代码: <?php class MyException extends Exception {} function global_exception_handler($exception) { switch (get_class($exception)) { case 'MyException': print "I am being handled in a unified way.\n"; break; default: $backtrace = debug_backtrace(); $exception_trace_object = $backtrace[0]['args'][0]; var_dump($exception_trace_object); print "----\n"; $reflected_exception_trace_object = new ReflectionObject($exception_trace_object); $reflected_trace_property = $reflected_exception_trace_object->getProperty('trace'); $reflected_trace_property->setAccessible(true); var_dump($reflected_trace_property); print "----\n"; // NOT WORKING, I STUCK HERE. var_dump($reflected_trace_property->getValue($reflected_trace_property)); throw $exception; } } set_exception_handler('global_exception_handler'); function function1() { function2(); } function function2() { function3(); } function function3() { throw new Exception(); } function1(); ?>_Php_Exception_Global_Handler - Fatal编程技术网

尝试在PHP中使用全局异常处理程序以统一的方式处理各种顶级异常 请考虑以下代码: <?php class MyException extends Exception {} function global_exception_handler($exception) { switch (get_class($exception)) { case 'MyException': print "I am being handled in a unified way.\n"; break; default: $backtrace = debug_backtrace(); $exception_trace_object = $backtrace[0]['args'][0]; var_dump($exception_trace_object); print "----\n"; $reflected_exception_trace_object = new ReflectionObject($exception_trace_object); $reflected_trace_property = $reflected_exception_trace_object->getProperty('trace'); $reflected_trace_property->setAccessible(true); var_dump($reflected_trace_property); print "----\n"; // NOT WORKING, I STUCK HERE. var_dump($reflected_trace_property->getValue($reflected_trace_property)); throw $exception; } } set_exception_handler('global_exception_handler'); function function1() { function2(); } function function2() { function3(); } function function3() { throw new Exception(); } function1(); ?>

尝试在PHP中使用全局异常处理程序以统一的方式处理各种顶级异常 请考虑以下代码: <?php class MyException extends Exception {} function global_exception_handler($exception) { switch (get_class($exception)) { case 'MyException': print "I am being handled in a unified way.\n"; break; default: $backtrace = debug_backtrace(); $exception_trace_object = $backtrace[0]['args'][0]; var_dump($exception_trace_object); print "----\n"; $reflected_exception_trace_object = new ReflectionObject($exception_trace_object); $reflected_trace_property = $reflected_exception_trace_object->getProperty('trace'); $reflected_trace_property->setAccessible(true); var_dump($reflected_trace_property); print "----\n"; // NOT WORKING, I STUCK HERE. var_dump($reflected_trace_property->getValue($reflected_trace_property)); throw $exception; } } set_exception_handler('global_exception_handler'); function function1() { function2(); } function function2() { function3(); } function function3() { throw new Exception(); } function1(); ?>,php,exception,global,handler,Php,Exception,Global,Handler,提前谢谢 查看评论,这里有几个类似的问题和解决方案。对于您的代码,我看到了两种可能的解决方案: 将代码更改为 function global_exception_handler($exception = NULL) 或者添加一个描述 throw new Exception('Testing here...'); 波塔克,你就是那个人!pinkgothic在参考页面上的例子似乎正是我一直在寻找的。非常感谢你!我完全忘了接受你的回答,很抱歉耽搁了这么久。 throw new Exception(

提前谢谢

查看评论,这里有几个类似的问题和解决方案。对于您的代码,我看到了两种可能的解决方案:

将代码更改为

function global_exception_handler($exception = NULL)
或者添加一个描述

throw new Exception('Testing here...');

波塔克,你就是那个人!pinkgothic在参考页面上的例子似乎正是我一直在寻找的。非常感谢你!我完全忘了接受你的回答,很抱歉耽搁了这么久。
throw new Exception('Testing here...');