Browse Source

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.
pull/204/merge
Nikita Popov 14 years ago
parent
commit
f28c128b20
  1. 9
      Zend/tests/bug60738.phpt
  2. 23
      Zend/tests/bug60738_variation.phpt
  3. 4
      Zend/zend_builtin_functions.c

9
Zend/tests/bug60738.phpt

@ -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

23
Zend/tests/bug60738_variation.phpt

@ -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

4
Zend/zend_builtin_functions.c

@ -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))

Loading…
Cancel
Save