Skip to content

Commit f1d0ead

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79487: ::getStaticProperties() ignores property modifications
2 parents f3b1f34 + a895bb6 commit f1d0ead

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

ext/reflection/php_reflection.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,9 +3845,7 @@ static void add_class_vars(zend_class_entry *ce, zend_bool statics, zval *return
38453845
zend_string *key;
38463846

38473847
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
3848-
if (((prop_info->flags & ZEND_ACC_PROTECTED) &&
3849-
!zend_check_protected(prop_info->ce, ce)) ||
3850-
((prop_info->flags & ZEND_ACC_PRIVATE) &&
3848+
if (((prop_info->flags & ZEND_ACC_PRIVATE) &&
38513849
prop_info->ce != ce)) {
38523850
continue;
38533851
}
@@ -3885,6 +3883,9 @@ ZEND_METHOD(ReflectionClass, getStaticProperties)
38853883
{
38863884
reflection_object *intern;
38873885
zend_class_entry *ce;
3886+
zend_property_info *prop_info;
3887+
zval *prop;
3888+
zend_string *key;
38883889

38893890
if (zend_parse_parameters_none() == FAILURE) {
38903891
RETURN_THROWS();
@@ -3896,8 +3897,34 @@ ZEND_METHOD(ReflectionClass, getStaticProperties)
38963897
return;
38973898
}
38983899

3900+
if (!CE_STATIC_MEMBERS(ce)) {
3901+
zend_class_init_statics(ce);
3902+
}
3903+
38993904
array_init(return_value);
3900-
add_class_vars(ce, 1, return_value);
3905+
3906+
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
3907+
if (((prop_info->flags & ZEND_ACC_PRIVATE) &&
3908+
prop_info->ce != ce)) {
3909+
continue;
3910+
}
3911+
if ((prop_info->flags & ZEND_ACC_STATIC) == 0) {
3912+
continue;
3913+
}
3914+
3915+
prop = &CE_STATIC_MEMBERS(ce)[prop_info->offset];
3916+
ZVAL_DEINDIRECT(prop);
3917+
3918+
if (prop_info->type && Z_ISUNDEF_P(prop)) {
3919+
continue;
3920+
}
3921+
3922+
/* enforce read only access */
3923+
ZVAL_DEREF(prop);
3924+
Z_TRY_ADDREF_P(prop);
3925+
3926+
zend_hash_update(Z_ARRVAL_P(return_value), key, prop);
3927+
} ZEND_HASH_FOREACH_END();
39013928
}
39023929
/* }}} */
39033930

ext/reflection/tests/bug79487.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #79487 (::getStaticProperties() ignores property modifications)
3+
--FILE--
4+
<?php
5+
class Foo {
6+
public static $bar = 'orig';
7+
}
8+
9+
Foo::$bar = 'new';
10+
$rc = new ReflectionClass('Foo');
11+
var_dump($rc->getStaticProperties());
12+
13+
class A {
14+
public static $a = 'A old';
15+
}
16+
class B extends A {
17+
public static $b = 'B old';
18+
}
19+
20+
$rc = new ReflectionClass(B::class);
21+
A::$a = 'A new';
22+
var_dump($rc->getStaticProperties());
23+
?>
24+
--EXPECT--
25+
array(1) {
26+
["bar"]=>
27+
string(3) "new"
28+
}
29+
array(2) {
30+
["b"]=>
31+
string(5) "B old"
32+
["a"]=>
33+
string(5) "A new"
34+
}

0 commit comments

Comments
 (0)