Skip to content

Commit 9d69ab9

Browse files
committed
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.
1 parent 216e87a commit 9d69ab9

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PHP NEWS
1212
. Fixed bug GH-19613 (Stale array iterator pointer). (ilutov)
1313
. Fixed bug GH-19679 (zend_ssa_range_widening may fail to converge). (Arnaud)
1414
. Fixed bug GH-19681 (PHP_EXPAND_PATH broken with bash 5.3.0). (Remi)
15+
. Fixed bug GH-19720 (Assertion failure when error handler throws when
16+
accessing a deprecated constant). (nielsdos)
1517

1618
- CLI:
1719
. Fixed bug GH-19461 (Improve error message on listening error with IPv6

Zend/zend_API.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,9 @@ ZEND_API zend_result zend_update_class_constant(zend_class_constant *c, const ze
14591459
zval_ptr_dtor(&c->value);
14601460
ZVAL_COPY_VALUE(&c->value, &tmp);
14611461

1462+
/* may not return SUCCESS in case of an exception,
1463+
* should've returned FAILURE in zval_update_constant_ex! */
1464+
ZEND_ASSERT(!EG(exception));
14621465
return SUCCESS;
14631466
}
14641467

Zend/zend_constants.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
536536

537537
if (!(flags & ZEND_FETCH_CLASS_SILENT) && (ZEND_CONSTANT_FLAGS(c) & CONST_DEPRECATED)) {
538538
zend_error(E_DEPRECATED, "Constant %s is deprecated", name);
539+
if (UNEXPECTED(EG(exception))) {
540+
return NULL;
541+
}
539542
}
540543
return &c->value;
541544
}

ext/zend_test/tests/gh19720.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-19720 (Assertion failure when error handler throws when accessing a deprecated constant)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
class Test {
8+
public const MyConst = [ZEND_TEST_DEPRECATED => 42];
9+
}
10+
11+
set_error_handler(function ($_, $errstr) {
12+
throw new Exception($errstr);
13+
});
14+
15+
try {
16+
var_dump(Test::MyConst);
17+
} catch (Exception $e) {
18+
echo $e->getMessage(), "\n";
19+
}
20+
?>
21+
--EXPECT--
22+
Constant ZEND_TEST_DEPRECATED is deprecated

0 commit comments

Comments
 (0)