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:
2
NEWS
2
NEWS
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
22
ext/zend_test/tests/gh19720.phpt
Normal file
22
ext/zend_test/tests/gh19720.phpt
Normal 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
|
||||
Reference in New Issue
Block a user