정말 쉬운 일은 아니지만 결국 나는 실수로 E_NOTICE
오류를 잡았습니다. 현재 error_handler
을 무시하고 예외를 throw하여 try{}
문을 catch해야했습니다.
function testGotUndefinedIndex() {
// Overriding the error handler
function errorHandlerCatchUndefinedIndex($errno, $errstr, $errfile, $errline) {
// We are only interested in one kind of error
if ($errstr=='Undefined index: bar') {
//We throw an exception that will be catched in the test
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
return false;
}
set_error_handler("errorHandlerCatchUndefinedIndex");
try {
// triggering the error
$foo = array();
echo $foo['bar'];
} catch (ErrorException $e) {
// Very important : restoring the previous error handler
restore_error_handler();
// Manually asserting that the test fails
$this->fail();
return;
}
// Very important : restoring the previous error handler
restore_error_handler();
// Manually asserting that the test succeed
$this->pass();
}
이것은 오류 처리기를 다시 선언해야만 예외를 잡아내어 잡는 데 약간 지나치게 복잡해 보입니다. 다른 어려운 부분은 예외가 catch되고 오류가 발생하지 않았을 때 error_handler를 올바르게 복원하고있었습니다. 그렇지 않으면 SimpleTest 오류 처리가 망가졌습니다.
얼마나 끔찍한 언어입니까? – m93a
E_NOTICE를 set_error_handler의 두 번째 매개 변수로 제공하면 알림 만 처리합니다. "error_reporting ini 설정이 표시되는 오류를 제어하는 것처럼 _error_handler_ 함수의 트리거링을 마스크하는 데 사용할 수 있습니다.이 마스크 세트가 없으면 error_reporting 설정에 관계없이 모든 오류에 대해 _error_handler_가 호출됩니다." – nick