dousi6405 2012-07-13 20:56
浏览 46
已采纳

调用undefined方法时不调用shutdown回调

Consider the following two PHP (5.4) scripts. Why is the callback passed to register_shutdown_function only invoked when script A is executed, but not when script B is executed?

Script A

set_error_handler(function() {
    throw new Exception();
});
register_shutdown_function(function() {
    echo "shutdown handler invoked
";
});

undefined();
// "shutdown handler invoked" IS displayed

Script B

set_error_handler(function() {
    throw new Exception();
});
register_shutdown_function(function() {
    echo "shutdown handler invoked
";
});

$undefined->undefined();
// "shutdown handler invoked" IS NOT displayed
  • 写回答

2条回答 默认 最新

  • duanli6834 2012-07-17 03:00
    关注

    It's a bug—if the callable registered with set_error_handler throws an exception, the shutdown function will not be invoked.

    In this particular case, the following chain of events happens:

    1. Non-fatal error is triggered (Undefined variable: undefined)
    2. User error handler is invoked
    3. Exception is thrown
    4. Fatal error is triggered (Call to a member function undefined() on a non-object)
    5. Shutdown function is not invoked, due to existing exception

    The existing bug reports at https://bugs.php.net/61767 (with patch!) and https://bugs.php.net/60909 have additional details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突