Commit:    4954aba2edbc4e29b8b18837298016b435ff7968
Author:    Nikita Popov <ni...@php.net>         Sat, 22 Sep 2012 21:41:51 +0200
Parents:   a31fa55b44bcb342c00e9ab2f4a851d054897a39
Branches:  master

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

Log:
Revert error/exception handler changes

This reverts the following two commits:

 * 6ba2e662e447f369c6e7686e8b39dde033fd5334
 * d8f8e98d8e0493adf1fae622595bd3435bdbf835

Laruence already did some partial changes to set_error_handler and
set_exception_handler. I'm reverting those modifications to apply the full
set of changes. (The modifications changed the code structure in a way that
would lead to more duplication with the new behavior.)

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


Diff:
diff --git a/Zend/tests/bug60738.phpt b/Zend/tests/bug60738.phpt
deleted file mode 100644
index e0c9793..0000000
--- a/Zend/tests/bug60738.phpt
+++ /dev/null
@@ -1,17 +0,0 @@
---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 f8d4674..eab98ed 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1512,6 +1512,7 @@ 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;
 
@@ -1519,41 +1520,38 @@ ZEND_FUNCTION(set_error_handler)
                return;
        }
 
-       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;
-               }
+       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);
 
-               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));
-               EG(user_error_handler_error_reporting) = (int)error_type;
-               MAKE_COPY_ZVAL(&error_handler, 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 (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 (!zend_is_true(error_handler)) { /* unset user-defined handler */
+               FREE_ZVAL(EG(user_error_handler));
                EG(user_error_handler) = NULL;
                RETURN_TRUE;
        }
+
+       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();
+       }
 }
 /* }}} */
 
@@ -1587,42 +1585,41 @@ ZEND_FUNCTION(set_exception_handler)
 {
        zval *exception_handler;
        char *exception_handler_name = NULL;
+       zend_bool had_orig_exception_handler=0;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", 
&exception_handler) == FAILURE) {
                return;
        }
 
        if (Z_TYPE_P(exception_handler) != IS_NULL) { /* NULL == unset */
-               zend_bool had_orig_exception_handler = 0;
-
                if (!zend_is_callable(exception_handler, 0, 
&exception_handler_name TSRMLS_CC)) {
                        zend_error(E_WARNING, "%s() expects the argument (%s) 
to be a valid callback",
-                                       get_active_function_name(TSRMLS_C), 
exception_handler_name?exception_handler_name:"unknown");
+                                          get_active_function_name(TSRMLS_C), 
exception_handler_name?exception_handler_name:"unknown");
                        efree(exception_handler_name);
                        return;
                }
                efree(exception_handler_name);
+       }
 
-               if (EG(user_exception_handler)) {
-                       had_orig_exception_handler = 1;
-                       *return_value = *EG(user_exception_handler);
-                       zval_copy_ctor(return_value);
-                       zend_ptr_stack_push(&EG(user_exception_handlers), 
EG(user_exception_handler));
-               }
-
-               ALLOC_ZVAL(EG(user_exception_handler));
-               MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler));
+       if (EG(user_exception_handler)) {
+               had_orig_exception_handler = 1;
+               *return_value = *EG(user_exception_handler);
+               zval_copy_ctor(return_value);
+               zend_ptr_stack_push(&EG(user_exception_handlers), 
EG(user_exception_handler));
+       }
+       ALLOC_ZVAL(EG(user_exception_handler));
 
-               if (!had_orig_exception_handler) {
-                       RETURN_NULL();
-               }
-       } else {
-               if (EG(user_exception_handler)) {
-                       zend_ptr_stack_push(&EG(user_exception_handlers), 
EG(user_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;
        }
+
+       MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler))
+
+       if (!had_orig_exception_handler) {
+               RETURN_NULL();
+       }
 }
 /* }}} */


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

Reply via email to