diff --git a/Zend/zend_API.c b/Zend/zend_API.c index fa5365b776d..4e3cdc597bf 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1520,6 +1520,9 @@ ZEND_API zend_result zend_update_class_constant(zend_class_constant *c, const ze zval_ptr_dtor(&c->value); ZVAL_COPY_VALUE(&c->value, &tmp); + /* may not return SUCCESS in case of an exception, + * should've returned FAILURE in zval_update_constant_ex! */ + ZEND_ASSERT(!EG(exception)); return SUCCESS; } diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c index efdcb905fd7..a18c393be7f 100644 --- a/Zend/zend_constants.c +++ b/Zend/zend_constants.c @@ -487,6 +487,9 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope, CONST_PROTECT_RECURSION(c); zend_deprecated_constant(c, c->name); CONST_UNPROTECT_RECURSION(c); + if (UNEXPECTED(EG(exception))) { + return NULL; + } } } return &c->value; diff --git a/ext/zend_test/tests/gh19720.phpt b/ext/zend_test/tests/gh19720.phpt new file mode 100644 index 00000000000..627444c4793 --- /dev/null +++ b/ext/zend_test/tests/gh19720.phpt @@ -0,0 +1,22 @@ +--TEST-- +GH-19720 (Assertion failure when error handler throws when accessing a deprecated constant) +--EXTENSIONS-- +zend_test +--FILE-- + 42]; +} + +set_error_handler(function ($_, $errstr) { + throw new Exception($errstr); +}); + +try { + var_dump(Test::MyConst); +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +} +?> +--EXPECT-- +Constant ZEND_TEST_DEPRECATED is deprecated