Skip to content

Commit 9d8f2a4

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-19720: Assertion failure when error handler throws when accessing a deprecated constant
2 parents 96c4d8b + c583124 commit 9d8f2a4

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Zend/zend_API.c

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

1523+
/* may not return SUCCESS in case of an exception,
1524+
* should've returned FAILURE in zval_update_constant_ex! */
1525+
ZEND_ASSERT(!EG(exception));
15231526
return SUCCESS;
15241527
}
15251528

Zend/zend_constants.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
487487
CONST_PROTECT_RECURSION(c);
488488
zend_deprecated_constant(c, c->name);
489489
CONST_UNPROTECT_RECURSION(c);
490+
if (UNEXPECTED(EG(exception))) {
491+
return NULL;
492+
}
490493
}
491494
}
492495
return &c->value;

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)