Skip to content

Commit 27d2fdd

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix GH-8080: ReflectionClass::getConstants() depends on def. order
2 parents 56d7672 + 0d266a2 commit 27d2fdd

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ PHP NEWS
2828
- MySQLnd:
2929
. Fixed bug GH-8058 (NULL pointer dereference in mysqlnd package). (Kamil Tekiela)
3030

31+
- Reflection:
32+
. Fixed bug GH-8080 (ReflectionClass::getConstants() depends on def. order).
33+
(cmb)
34+
3135
- Zlib:
3236
. Fixed bug GH-7953 (ob_clean() only does not set Content-Encoding). (cmb)
3337

ext/reflection/php_reflection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4637,7 +4637,7 @@ ZEND_METHOD(ReflectionClass, getConstants)
46374637

46384638
array_init(return_value);
46394639
ZEND_HASH_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), key, constant) {
4640-
if (UNEXPECTED(zval_update_constant_ex(&constant->value, ce) != SUCCESS)) {
4640+
if (UNEXPECTED(zval_update_constant_ex(&constant->value, constant->ce) != SUCCESS)) {
46414641
RETURN_THROWS();
46424642
}
46434643

@@ -4696,7 +4696,7 @@ ZEND_METHOD(ReflectionClass, getConstant)
46964696
GET_REFLECTION_OBJECT_PTR(ce);
46974697
constants_table = CE_CONSTANTS_TABLE(ce);
46984698
ZEND_HASH_FOREACH_PTR(constants_table, c) {
4699-
if (UNEXPECTED(zval_update_constant_ex(&c->value, ce) != SUCCESS)) {
4699+
if (UNEXPECTED(zval_update_constant_ex(&c->value, c->ce) != SUCCESS)) {
47004700
RETURN_THROWS();
47014701
}
47024702
} ZEND_HASH_FOREACH_END();

ext/reflection/tests/gh8080.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
GH-8080 (ReflectionClass::getConstants() depends on def. order)
3+
--FILE--
4+
<?php
5+
class A {
6+
const LIST = [
7+
self::TEST => 'Test',
8+
];
9+
private const TEST = 'test';
10+
}
11+
12+
class B extends A {}
13+
14+
$r = new ReflectionClass(B::class);
15+
var_dump(
16+
$r->getConstants(),
17+
$r->getConstant("LIST")
18+
);
19+
?>
20+
--EXPECT--
21+
array(1) {
22+
["LIST"]=>
23+
array(1) {
24+
["test"]=>
25+
string(4) "Test"
26+
}
27+
}
28+
array(1) {
29+
["test"]=>
30+
string(4) "Test"
31+
}

0 commit comments

Comments
 (0)