com php-src: Allow resetting the error handler: Zend/tests/bug60738.phpt Zend/zend_builtin_functions.c
| From: | Nikita Popov | Date: | Sat, 22 Sep 2012 19:46:02 +0000 |
| Subject: | com php-src: Allow resetting the error handler: Zend/tests/bug60738.phpt Zend/zend_builtin_functions.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-70225@lists.php.net to get a copy of this message | ||
Commit: c815dd74bc42c8f36ba35b910f45e85a645d7e3d
Author: Nikita Popov <nikic@php.net> Sat, 24 Mar 2012 12:52:15 +0100
Parents: 4954aba2edbc4e29b8b18837298016b435ff7968
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c815dd74bc42c8f36ba35b910f45e85a645d7e3d
Log:
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.
Changed paths:
A Zend/tests/bug60738.phpt
M Zend/zend_builtin_functions.c
Diff:
diff --git a/Zend/tests/bug60738.phpt b/Zend/tests/bug60738.phpt
new file mode 100644
index 0000000..e0c9793
--- /dev/null
+++ b/Zend/tests/bug60738.phpt
@@ -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
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index eab98ed..204c7d3 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -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;
@@ -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;