在file1.php:ErrorException返回錯誤的文件和行
set_error_handler('my_error_handler');
set_exception_handler('my_exception_handler');
function my_error_handler($errNo, $errStr, $errFile, $errLine, $whatever = null){
// here ErrFile and $errLine are correct only for native funcs...
throw New ErrorException($errStr, 0, $errNo, $errFile, $errLine);
}
function my_exception_handler($exception){
print $exception->getLine(); // correct only for native functions
print $exception->getFile(); // correct only for native functions
}
在file2.php,一個例子函數定義:
function foo($requiredArg){
}
和file3.php,調用foo:
foo();
產生:
foo的(),稱爲file3.php第2行和定義 缺少的參數1 ...
的訊息話題是正確的,但是當我試圖讓該文件並符合$exception->getFile()
和$exception->getLine()
(在我的異常處理程序中),我得到了定義foo()的文件和行,而不是它被調用的地方...
但是使用本地PHP函數,我得到了函數被調用的文件和行是我想要的)。
當你的錯誤處理程序被調用時,你能否確認你得到了正確的文件名和行號? – nickb 2012-07-20 17:01:27
不,我得到相同的文件和行:(這是否意味着PHP將錯誤的參數傳遞給我的錯誤處理程序? – Alex 2012-07-20 17:02:39