mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Allow resetting the error handler
This allows the error handler to be reset using set_error_handler(null). As the code suggests this behavior was already previously intended, but the callback check was done too strictly.
This commit is contained in:
parent
4954aba2ed
commit
c815dd74bc
2 changed files with 25 additions and 6 deletions
17
Zend/tests/bug60738.phpt
Normal file
17
Zend/tests/bug60738.phpt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #60738 Allow 'set_error_handler' to handle NULL
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
set_error_handler(function() { echo 'Intercepted error!', "\n"; });
|
||||||
|
|
||||||
|
trigger_error('Error!');
|
||||||
|
|
||||||
|
set_error_handler(null);
|
||||||
|
|
||||||
|
trigger_error('Error!');
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Intercepted error!
|
||||||
|
|
||||||
|
Notice: Error! in %s on line %d
|
|
@ -1520,13 +1520,15 @@ ZEND_FUNCTION(set_error_handler)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!zend_is_callable(error_handler, 0, &error_handler_name TSRMLS_CC)) {
|
if (Z_TYPE_P(error_handler) != IS_NULL) { /* NULL == unset */
|
||||||
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
|
if (!zend_is_callable(error_handler, 0, &error_handler_name TSRMLS_CC)) {
|
||||||
get_active_function_name(TSRMLS_C), error_handler_name?error_handler_name:"unknown");
|
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
|
||||||
|
get_active_function_name(TSRMLS_C), error_handler_name?error_handler_name:"unknown");
|
||||||
|
efree(error_handler_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
efree(error_handler_name);
|
efree(error_handler_name);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
efree(error_handler_name);
|
|
||||||
|
|
||||||
if (EG(user_error_handler)) {
|
if (EG(user_error_handler)) {
|
||||||
had_orig_error_handler = 1;
|
had_orig_error_handler = 1;
|
||||||
|
@ -1538,7 +1540,7 @@ ZEND_FUNCTION(set_error_handler)
|
||||||
}
|
}
|
||||||
ALLOC_ZVAL(EG(user_error_handler));
|
ALLOC_ZVAL(EG(user_error_handler));
|
||||||
|
|
||||||
if (!zend_is_true(error_handler)) { /* unset user-defined handler */
|
if (Z_TYPE_P(error_handler) == IS_NULL) { /* unset user-defined handler */
|
||||||
FREE_ZVAL(EG(user_error_handler));
|
FREE_ZVAL(EG(user_error_handler));
|
||||||
EG(user_error_handler) = NULL;
|
EG(user_error_handler) = NULL;
|
||||||
RETURN_TRUE;
|
RETURN_TRUE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue