mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
Fix #79487: ::getStaticProperties() ignores property modifications
When retrieving the static class properties via reflection, we have to cater to possible modifications.
This commit is contained in:
parent
f3cccfde9e
commit
ef2130db88
3 changed files with 69 additions and 4 deletions
4
NEWS
4
NEWS
|
@ -5,6 +5,10 @@ PHP NEWS
|
||||||
- FTP:
|
- FTP:
|
||||||
. Fixed bug #55857 (ftp_size on large files). (cmb)
|
. Fixed bug #55857 (ftp_size on large files). (cmb)
|
||||||
|
|
||||||
|
- Reflection:
|
||||||
|
. Fixed bug #79487 (::getStaticProperties() ignores property modifications).
|
||||||
|
(cmb, Nikita)
|
||||||
|
|
||||||
?? ??? 2020, PHP 7.4.8
|
?? ??? 2020, PHP 7.4.8
|
||||||
|
|
||||||
- Core:
|
- Core:
|
||||||
|
|
|
@ -3726,9 +3726,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value
|
||||||
zend_string *key;
|
zend_string *key;
|
||||||
|
|
||||||
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
|
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
|
||||||
if (((prop_info->flags & ZEND_ACC_PROTECTED) &&
|
if (((prop_info->flags & ZEND_ACC_PRIVATE) &&
|
||||||
!zend_check_protected(prop_info->ce, ce)) ||
|
|
||||||
((prop_info->flags & ZEND_ACC_PRIVATE) &&
|
|
||||||
prop_info->ce != ce)) {
|
prop_info->ce != ce)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -3766,6 +3764,9 @@ ZEND_METHOD(reflection_class, getStaticProperties)
|
||||||
{
|
{
|
||||||
reflection_object *intern;
|
reflection_object *intern;
|
||||||
zend_class_entry *ce;
|
zend_class_entry *ce;
|
||||||
|
zend_property_info *prop_info;
|
||||||
|
zval *prop;
|
||||||
|
zend_string *key;
|
||||||
|
|
||||||
if (zend_parse_parameters_none() == FAILURE) {
|
if (zend_parse_parameters_none() == FAILURE) {
|
||||||
return;
|
return;
|
||||||
|
@ -3777,8 +3778,34 @@ ZEND_METHOD(reflection_class, getStaticProperties)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ce->default_static_members_count && !CE_STATIC_MEMBERS(ce)) {
|
||||||
|
zend_class_init_statics(ce);
|
||||||
|
}
|
||||||
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
add_class_vars(ce, 1, return_value);
|
|
||||||
|
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
|
||||||
|
if (((prop_info->flags & ZEND_ACC_PRIVATE) &&
|
||||||
|
prop_info->ce != ce)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((prop_info->flags & ZEND_ACC_STATIC) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
prop = &CE_STATIC_MEMBERS(ce)[prop_info->offset];
|
||||||
|
ZVAL_DEINDIRECT(prop);
|
||||||
|
|
||||||
|
if (prop_info->type && Z_ISUNDEF_P(prop)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* enforce read only access */
|
||||||
|
ZVAL_DEREF(prop);
|
||||||
|
Z_TRY_ADDREF_P(prop);
|
||||||
|
|
||||||
|
zend_hash_update(Z_ARRVAL_P(return_value), key, prop);
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
34
ext/reflection/tests/bug79487.phpt
Normal file
34
ext/reflection/tests/bug79487.phpt
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #79487 (::getStaticProperties() ignores property modifications)
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
class Foo {
|
||||||
|
public static $bar = 'orig';
|
||||||
|
}
|
||||||
|
|
||||||
|
Foo::$bar = 'new';
|
||||||
|
$rc = new ReflectionClass('Foo');
|
||||||
|
var_dump($rc->getStaticProperties());
|
||||||
|
|
||||||
|
class A {
|
||||||
|
public static $a = 'A old';
|
||||||
|
}
|
||||||
|
class B extends A {
|
||||||
|
public static $b = 'B old';
|
||||||
|
}
|
||||||
|
|
||||||
|
$rc = new ReflectionClass(B::class);
|
||||||
|
A::$a = 'A new';
|
||||||
|
var_dump($rc->getStaticProperties());
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
array(1) {
|
||||||
|
["bar"]=>
|
||||||
|
string(3) "new"
|
||||||
|
}
|
||||||
|
array(2) {
|
||||||
|
["b"]=>
|
||||||
|
string(5) "B old"
|
||||||
|
["a"]=>
|
||||||
|
string(5) "A new"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue