Return previous error handler when resetting the error handler

set_error_handler(null) and set_exception_handler(null) now return the
previous error/exception handler instead of just returning bool(true).
This is consistent with the behavior of these functions with non-null
values.
This commit is contained in:
Nikita Popov 2012-03-24 13:10:51 +01:00
parent c815dd74bc
commit f28c128b20
3 changed files with 32 additions and 4 deletions

View File

@ -3,15 +3,20 @@ Bug #60738 Allow 'set_error_handler' to handle NULL
--FILE--
<?php
set_error_handler(function() { echo 'Intercepted error!', "\n"; });
var_dump(set_error_handler(
function() { echo 'Intercepted error!', "\n"; }
));
trigger_error('Error!');
set_error_handler(null);
var_dump(set_error_handler(null));
trigger_error('Error!');
?>
--EXPECTF--
NULL
Intercepted error!
object(Closure)#1 (0) {
}
Notice: Error! in %s on line %d

View File

@ -0,0 +1,23 @@
--TEST--
Bug #60738 Allow 'set_error_handler' to handle NULL
--FILE--
<?php
var_dump(set_exception_handler(
function() { echo 'Intercepted exception!', "\n"; }
));
var_dump(set_exception_handler(null));
throw new Exception('Exception!');
?>
--EXPECTF--
NULL
object(Closure)#1 (0) {
}
Fatal error: Uncaught exception 'Exception' with message 'Exception!' in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d

View File

@ -1543,7 +1543,7 @@ ZEND_FUNCTION(set_error_handler)
if (Z_TYPE_P(error_handler) == IS_NULL) { /* unset user-defined handler */
FREE_ZVAL(EG(user_error_handler));
EG(user_error_handler) = NULL;
RETURN_TRUE;
return;
}
EG(user_error_handler_error_reporting) = (int)error_type;
@ -1614,7 +1614,7 @@ ZEND_FUNCTION(set_exception_handler)
if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */
FREE_ZVAL(EG(user_exception_handler));
EG(user_exception_handler) = NULL;
RETURN_TRUE;
return;
}
MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler))