Skip to content

Commit 4954aba

Browse files
committed
Revert error/exception handler changes
This reverts the following two commits: * 6ba2e66 * d8f8e98 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.)
1 parent a31fa55 commit 4954aba

File tree

2 files changed

+45
-65
lines changed

2 files changed

+45
-65
lines changed

Zend/tests/bug60738.phpt

Lines changed: 0 additions & 17 deletions
This file was deleted.

Zend/zend_builtin_functions.c

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,48 +1512,46 @@ ZEND_FUNCTION(trigger_error)
15121512
ZEND_FUNCTION(set_error_handler)
15131513
{
15141514
zval *error_handler;
1515+
zend_bool had_orig_error_handler=0;
15151516
char *error_handler_name = NULL;
15161517
long error_type = E_ALL;
15171518

15181519
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &error_handler, &error_type) == FAILURE) {
15191520
return;
15201521
}
15211522

1522-
if (IS_NULL != Z_TYPE_P(error_handler)) {
1523-
zend_bool had_orig_error_handler = 0;
1524-
if (!zend_is_callable(error_handler, 0, &error_handler_name TSRMLS_CC)) {
1525-
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
1526-
get_active_function_name(TSRMLS_C), error_handler_name?error_handler_name:"unknown");
1527-
efree(error_handler_name);
1528-
return;
1529-
}
1523+
if (!zend_is_callable(error_handler, 0, &error_handler_name TSRMLS_CC)) {
1524+
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
1525+
get_active_function_name(TSRMLS_C), error_handler_name?error_handler_name:"unknown");
15301526
efree(error_handler_name);
1527+
return;
1528+
}
1529+
efree(error_handler_name);
15311530

1532-
if (EG(user_error_handler)) {
1533-
had_orig_error_handler = 1;
1534-
*return_value = *EG(user_error_handler);
1535-
zval_copy_ctor(return_value);
1536-
INIT_PZVAL(return_value);
1537-
zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting), sizeof(EG(user_error_handler_error_reporting)));
1538-
zend_ptr_stack_push(&EG(user_error_handlers), EG(user_error_handler));
1539-
}
1540-
1541-
ALLOC_ZVAL(EG(user_error_handler));
1542-
EG(user_error_handler_error_reporting) = (int)error_type;
1543-
MAKE_COPY_ZVAL(&error_handler, EG(user_error_handler));
1544-
1545-
if (!had_orig_error_handler) {
1546-
RETURN_NULL();
1547-
}
1548-
} else { /* unset user-defined handler */
1549-
if (EG(user_error_handler)) {
1550-
zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting), sizeof(EG(user_error_handler_error_reporting)));
1551-
zend_ptr_stack_push(&EG(user_error_handlers), EG(user_error_handler));
1552-
}
1531+
if (EG(user_error_handler)) {
1532+
had_orig_error_handler = 1;
1533+
*return_value = *EG(user_error_handler);
1534+
zval_copy_ctor(return_value);
1535+
INIT_PZVAL(return_value);
1536+
zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting), sizeof(EG(user_error_handler_error_reporting)));
1537+
zend_ptr_stack_push(&EG(user_error_handlers), EG(user_error_handler));
1538+
}
1539+
ALLOC_ZVAL(EG(user_error_handler));
15531540

1541+
if (!zend_is_true(error_handler)) { /* unset user-defined handler */
1542+
FREE_ZVAL(EG(user_error_handler));
15541543
EG(user_error_handler) = NULL;
15551544
RETURN_TRUE;
15561545
}
1546+
1547+
EG(user_error_handler_error_reporting) = (int)error_type;
1548+
*EG(user_error_handler) = *error_handler;
1549+
zval_copy_ctor(EG(user_error_handler));
1550+
INIT_PZVAL(EG(user_error_handler));
1551+
1552+
if (!had_orig_error_handler) {
1553+
RETURN_NULL();
1554+
}
15571555
}
15581556
/* }}} */
15591557

@@ -1587,42 +1585,41 @@ ZEND_FUNCTION(set_exception_handler)
15871585
{
15881586
zval *exception_handler;
15891587
char *exception_handler_name = NULL;
1588+
zend_bool had_orig_exception_handler=0;
15901589

15911590
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &exception_handler) == FAILURE) {
15921591
return;
15931592
}
15941593

15951594
if (Z_TYPE_P(exception_handler) != IS_NULL) { /* NULL == unset */
1596-
zend_bool had_orig_exception_handler = 0;
1597-
15981595
if (!zend_is_callable(exception_handler, 0, &exception_handler_name TSRMLS_CC)) {
15991596
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
1600-
get_active_function_name(TSRMLS_C), exception_handler_name?exception_handler_name:"unknown");
1597+
get_active_function_name(TSRMLS_C), exception_handler_name?exception_handler_name:"unknown");
16011598
efree(exception_handler_name);
16021599
return;
16031600
}
16041601
efree(exception_handler_name);
1602+
}
16051603

1606-
if (EG(user_exception_handler)) {
1607-
had_orig_exception_handler = 1;
1608-
*return_value = *EG(user_exception_handler);
1609-
zval_copy_ctor(return_value);
1610-
zend_ptr_stack_push(&EG(user_exception_handlers), EG(user_exception_handler));
1611-
}
1612-
1613-
ALLOC_ZVAL(EG(user_exception_handler));
1614-
MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler));
1604+
if (EG(user_exception_handler)) {
1605+
had_orig_exception_handler = 1;
1606+
*return_value = *EG(user_exception_handler);
1607+
zval_copy_ctor(return_value);
1608+
zend_ptr_stack_push(&EG(user_exception_handlers), EG(user_exception_handler));
1609+
}
1610+
ALLOC_ZVAL(EG(user_exception_handler));
16151611

1616-
if (!had_orig_exception_handler) {
1617-
RETURN_NULL();
1618-
}
1619-
} else {
1620-
if (EG(user_exception_handler)) {
1621-
zend_ptr_stack_push(&EG(user_exception_handlers), EG(user_exception_handler));
1622-
}
1612+
if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */
1613+
FREE_ZVAL(EG(user_exception_handler));
16231614
EG(user_exception_handler) = NULL;
16241615
RETURN_TRUE;
16251616
}
1617+
1618+
MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler))
1619+
1620+
if (!had_orig_exception_handler) {
1621+
RETURN_NULL();
1622+
}
16261623
}
16271624
/* }}} */
16281625

0 commit comments

Comments
 (0)