Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow resetting error handler (#60738) #17

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Zend/tests/bug60738.phpt
Original file line number Diff line number Diff line change
@@ -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
14 changes: 8 additions & 6 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1520,13 +1520,15 @@ ZEND_FUNCTION(set_error_handler)
return;
}

if (!zend_is_callable(error_handler, 0, &error_handler_name TSRMLS_CC)) {
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");
if (Z_TYPE_P(error_handler) != IS_NULL) { /* NULL == unset */
if (!zend_is_callable(error_handler, 0, &error_handler_name TSRMLS_CC)) {
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);
return;
}
efree(error_handler_name);

if (EG(user_error_handler)) {
had_orig_error_handler = 1;
Expand All @@ -1538,7 +1540,7 @@ ZEND_FUNCTION(set_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));
EG(user_error_handler) = NULL;
RETURN_TRUE;
Expand Down