Skip to content

Commit 45ed9b4

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Improve error_handing replacement functions
2 parents 5ae657b + e948188 commit 45ed9b4

File tree

1 file changed

+4
-41
lines changed

1 file changed

+4
-41
lines changed

Zend/zend_API.c

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,62 +4367,25 @@ ZEND_API void zend_save_error_handling(zend_error_handling *current) /* {{{ */
43674367
{
43684368
current->handling = EG(error_handling);
43694369
current->exception = EG(exception_class);
4370-
ZVAL_COPY(&current->user_handler, &EG(user_error_handler));
4370+
ZVAL_UNDEF(&current->user_handler);
43714371
}
43724372
/* }}} */
43734373

43744374
ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current) /* {{{ */
43754375
{
43764376
if (current) {
43774377
zend_save_error_handling(current);
4378-
if (error_handling != EH_NORMAL && Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
4379-
zval_ptr_dtor(&EG(user_error_handler));
4380-
ZVAL_UNDEF(&EG(user_error_handler));
4381-
}
43824378
}
4379+
ZEND_ASSERT(error_handling == EH_THROW || exception_class == NULL);
43834380
EG(error_handling) = error_handling;
4384-
EG(exception_class) = error_handling == EH_THROW ? exception_class : NULL;
4385-
}
4386-
/* }}} */
4387-
4388-
static int same_zval(zval *zv1, zval *zv2) /* {{{ */
4389-
{
4390-
if (Z_TYPE_P(zv1) != Z_TYPE_P(zv2)) {
4391-
return 0;
4392-
}
4393-
switch (Z_TYPE_P(zv1)) {
4394-
case IS_UNDEF:
4395-
case IS_NULL:
4396-
case IS_FALSE:
4397-
case IS_TRUE:
4398-
return 1;
4399-
case IS_LONG:
4400-
return Z_LVAL_P(zv1) == Z_LVAL_P(zv2);
4401-
case IS_DOUBLE:
4402-
return Z_LVAL_P(zv1) == Z_LVAL_P(zv2);
4403-
case IS_STRING:
4404-
case IS_ARRAY:
4405-
case IS_OBJECT:
4406-
case IS_RESOURCE:
4407-
return Z_COUNTED_P(zv1) == Z_COUNTED_P(zv2);
4408-
default:
4409-
return 0;
4410-
}
4381+
EG(exception_class) = exception_class;
44114382
}
44124383
/* }}} */
44134384

44144385
ZEND_API void zend_restore_error_handling(zend_error_handling *saved) /* {{{ */
44154386
{
44164387
EG(error_handling) = saved->handling;
4417-
EG(exception_class) = saved->handling == EH_THROW ? saved->exception : NULL;
4418-
if (Z_TYPE(saved->user_handler) != IS_UNDEF
4419-
&& !same_zval(&saved->user_handler, &EG(user_error_handler))) {
4420-
zval_ptr_dtor(&EG(user_error_handler));
4421-
ZVAL_COPY_VALUE(&EG(user_error_handler), &saved->user_handler);
4422-
} else if (Z_TYPE(saved->user_handler)) {
4423-
zval_ptr_dtor(&saved->user_handler);
4424-
}
4425-
ZVAL_UNDEF(&saved->user_handler);
4388+
EG(exception_class) = saved->exception;
44264389
}
44274390
/* }}} */
44284391

0 commit comments

Comments
 (0)