Commit:    6ba2e662e447f369c6e7686e8b39dde033fd5334
Author:    Xinchen Hui <larue...@gmail.com>         Sat, 24 Mar 2012 19:41:11 
+0800
Parents:   d8f8e98d8e0493adf1fae622595bd3435bdbf835
Branches:  master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=6ba2e662e447f369c6e7686e8b39dde033fd5334

Log:
Implemented FR #60738 (Allow 'set_error_handler' to handle NULL)

The previous commit was reverted as Stas ask, so only commit this
to Truk now.

Bugs:
https://bugs.php.net/60738

Changed paths:
  M  NEWS
  A  Zend/tests/bug60738.phpt
  M  Zend/zend_builtin_functions.c


Diff:
6ba2e662e447f369c6e7686e8b39dde033fd5334
diff --git a/NEWS b/NEWS
index 9f1d520..089d080 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,10 @@ PHP                                                            
            NEWS
   . World domination
   . Improve set_exception_handler while doing reset.(Laruence)
 
+- Core:
+  . Implemented FR #60738 (Allow 'set_error_handler' to handle NULL).
+    (Laruence, Nikita Popov)
+
 - cURL:
   . Added support for CURLOPT_FTP_RESPONSE_TIMEOUT, CURLOPT_APPEND, 
     CURLOPT_DIRLISTONLY, CURLOPT_NEW_DIRECTORY_PERMS, CURLOPT_NEW_FILE_PERMS, 
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 29f9ed3..f8d4674 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1512,7 +1512,6 @@ ZEND_FUNCTION(trigger_error)
 ZEND_FUNCTION(set_error_handler)
 {
        zval *error_handler;
-       zend_bool had_orig_error_handler=0;
        char *error_handler_name = NULL;
        long error_type = E_ALL;
 
@@ -1520,37 +1519,40 @@ 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 (IS_NULL != Z_TYPE_P(error_handler)) {
+           zend_bool had_orig_error_handler = 0;
+               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;
-               *return_value = *EG(user_error_handler);
-               zval_copy_ctor(return_value);
-               INIT_PZVAL(return_value);
-               zend_stack_push(&EG(user_error_handlers_error_reporting), 
&EG(user_error_handler_error_reporting), 
sizeof(EG(user_error_handler_error_reporting)));
-               zend_ptr_stack_push(&EG(user_error_handlers), 
EG(user_error_handler));
-       }
-       ALLOC_ZVAL(EG(user_error_handler));
+               if (EG(user_error_handler)) {
+                       had_orig_error_handler = 1;
+                       *return_value = *EG(user_error_handler);
+                       zval_copy_ctor(return_value);
+                       INIT_PZVAL(return_value);
+                       
zend_stack_push(&EG(user_error_handlers_error_reporting), 
&EG(user_error_handler_error_reporting), 
sizeof(EG(user_error_handler_error_reporting)));
+                       zend_ptr_stack_push(&EG(user_error_handlers), 
EG(user_error_handler));
+               }
 
-       if (!zend_is_true(error_handler)) { /* unset user-defined handler */
-               FREE_ZVAL(EG(user_error_handler));
-               EG(user_error_handler) = NULL;
-               RETURN_TRUE;
-       }
+               ALLOC_ZVAL(EG(user_error_handler));
+               EG(user_error_handler_error_reporting) = (int)error_type;
+               MAKE_COPY_ZVAL(&error_handler, EG(user_error_handler));
 
-       EG(user_error_handler_error_reporting) = (int)error_type;
-       *EG(user_error_handler) = *error_handler;
-       zval_copy_ctor(EG(user_error_handler));
-       INIT_PZVAL(EG(user_error_handler));
+               if (!had_orig_error_handler) {
+                       RETURN_NULL();
+               }
+       } else { /* unset user-defined handler */
+               if (EG(user_error_handler)) {
+                       
zend_stack_push(&EG(user_error_handlers_error_reporting), 
&EG(user_error_handler_error_reporting), 
sizeof(EG(user_error_handler_error_reporting)));
+                       zend_ptr_stack_push(&EG(user_error_handlers), 
EG(user_error_handler));
+               }
 
-       if (!had_orig_error_handler) {
-               RETURN_NULL();
+               EG(user_error_handler) = NULL;
+               RETURN_TRUE;
        }
 }
 /* }}} */


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to