set_error_handler function not calling autoload

会有一股神秘感。 提交于 2019-12-22 08:26:04

问题


I have the set_error_handler() function set to call a function when there is an error.

In that function I have my own implementation of the exception class:

function acs_error_handler($errno, $errstr, $errfile, $errline) {    
    throw new acs_exception($errstr, $errno);     
}

This gives me the following error:

Fatal error: Class 'acs_exception' not found

For some reason, this function does not call my autoload function which I have set up using:

spl_autoload_register('__autoload');

If I add the line:

__autoload('acs_exception');

before calling the class in the error function it all works.

My question is: Shouldn't the __autoload() function fire when I call the acs_exception class in the error trigger function??


回答1:


Here's a related PHP bug report.

Your error is triggered at compile-time, which disables autoload (and spl_autoload at the same time).

Won't be fixed for PHP5.3 as it may cause lots of other problems.




回答2:


This was fixed on PHP 5.4.21 - now the SPL autoload functions are also triggered from error handling functions! :)



来源:https://stackoverflow.com/questions/1942507/set-error-handler-function-not-calling-autoload

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!