]> granicus.if.org Git - php/commitdiff
Return previous error handler when resetting the error handler
authorNikita Popov <nikic@php.net>
Sat, 24 Mar 2012 12:10:51 +0000 (13:10 +0100)
committerNikita Popov <nikic@php.net>
Sat, 22 Sep 2012 19:46:18 +0000 (21:46 +0200)
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.

Zend/tests/bug60738.phpt
Zend/tests/bug60738_variation.phpt [new file with mode: 0644]
Zend/zend_builtin_functions.c

index e0c9793fedf270e84108408090f2cb7205e675eb..e4080715ec72aad351375f49b0340f8e7de00a13 100644 (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
diff --git a/Zend/tests/bug60738_variation.phpt b/Zend/tests/bug60738_variation.phpt
new file mode 100644 (file)
index 0000000..d7cf00e
--- /dev/null
@@ -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
+
index 204c7d3d0b889836b1dbef12f1bc350ec40e4c3f..fdfe3db8f83b9495d76c49a99a137d0db0c35cfb 100644 (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))