1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-19720: Assertion failure when error handler throws when accessing a deprecated constant

When deprecation causes an exception, we should return NULL instead of
continuing.

Closes GH-19723.
This commit is contained in:
Niels Dossche
2025-09-05 18:53:43 +02:00
parent 216e87ad7e
commit 9d69ab91ab
4 changed files with 30 additions and 0 deletions

2
NEWS
View File

@@ -12,6 +12,8 @@ PHP NEWS
. Fixed bug GH-19613 (Stale array iterator pointer). (ilutov)
. Fixed bug GH-19679 (zend_ssa_range_widening may fail to converge). (Arnaud)
. Fixed bug GH-19681 (PHP_EXPAND_PATH broken with bash 5.3.0). (Remi)
. Fixed bug GH-19720 (Assertion failure when error handler throws when
accessing a deprecated constant). (nielsdos)
- CLI:
. Fixed bug GH-19461 (Improve error message on listening error with IPv6

View File

@@ -1459,6 +1459,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;
}

View File

@@ -536,6 +536,9 @@ failure:
if (!(flags & ZEND_FETCH_CLASS_SILENT) && (ZEND_CONSTANT_FLAGS(c) & CONST_DEPRECATED)) {
zend_error(E_DEPRECATED, "Constant %s is deprecated", name);
if (UNEXPECTED(EG(exception))) {
return NULL;
}
}
return &c->value;
}

View File

@@ -0,0 +1,22 @@
--TEST--
GH-19720 (Assertion failure when error handler throws when accessing a deprecated constant)
--EXTENSIONS--
zend_test
--FILE--
<?php
class Test {
public const MyConst = [ZEND_TEST_DEPRECATED => 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