2009-12-21 74 views
4

我有set_error_handler()函數設置爲在發生錯誤時調用函數。set_error_handler函數不調用自動加載

在這種功能,我有我自己實現的異常類:

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

這給了我下面的錯誤:

Fatal error: Class 'acs_exception' not found

出於某種原因,該功能不叫我的自動加載功能我已經設置使用:

spl_autoload_register('__autoload'); 

如果我添加行:

__autoload('acs_exception'); 

在調用錯誤函數中的類之前,它都可以工作。

我的問題是:當我在錯誤觸發函數中調用acs_exception類時,應該不會觸發__autoload()函數?

+1

順便說一句,您可以在名稱之前連續指定多少個下劃線,然後難以確切知道有多少個下劃線? – 2009-12-21 20:45:12

+0

我不得不添加額外的_因爲預覽變得混亂了。 – AntonioCS 2009-12-21 20:59:03

回答

3

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.

+0

太好了...... :( 感謝您的信息 – AntonioCS 2009-12-21 21:43:24

+0

我通過直接調用自動加載函數糾正了問題:)再次感謝 – AntonioCS 2009-12-22 00:03:00

1

這固定在PHP 5.4.21上 - 現在SPL自動加載函數也從錯誤處理函數中觸發! :)