]> granicus.if.org Git - php/commitdiff
Revert "Fix #79487: ::getStaticProperties() ignores property modifications"
authorChristoph M. Becker <cmbecker69@gmx.de>
Tue, 23 Jun 2020 17:28:51 +0000 (19:28 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Tue, 23 Jun 2020 17:28:51 +0000 (19:28 +0200)
This reverts commit a895bb6885fbceea3e8375816969d5510d8d082e.

NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/bug79487.phpt [deleted file]

diff --git a/NEWS b/NEWS
index a2e1aca9537249190d60dbe49036eb37492b3865..61513e9174b3a595601cea9a3f7c1919dedaff60 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,10 +5,6 @@ PHP                                                                        NEWS
 - FTP:
   . Fixed bug #55857 (ftp_size on large files). (cmb)
 
-- Reflection:
-  . Fixed bug #79487 (::getStaticProperties() ignores property modifications).
-    (cmb, Nikita)
-
 ?? ??? 2020, PHP 7.4.8
 
 - Core:
index 97066fb13ee37547bf1d9d52289a8c33b0073c82..dbfb67386e9bf2e73ff257b5029e7ff80a3d82af 100644 (file)
@@ -3726,7 +3726,9 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value
        zend_string *key;
 
        ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) {
-               if (((prop_info->flags & ZEND_ACC_PRIVATE) &&
+               if (((prop_info->flags & ZEND_ACC_PROTECTED) &&
+                    !zend_check_protected(prop_info->ce, ce)) ||
+                   ((prop_info->flags & ZEND_ACC_PRIVATE) &&
                     prop_info->ce != ce)) {
                        continue;
                }
@@ -3764,9 +3766,6 @@ ZEND_METHOD(reflection_class, getStaticProperties)
 {
        reflection_object *intern;
        zend_class_entry *ce;
-       zend_property_info *prop_info;
-       zval *prop;
-       zend_string *key;
 
        if (zend_parse_parameters_none() == FAILURE) {
                return;
@@ -3778,34 +3777,8 @@ ZEND_METHOD(reflection_class, getStaticProperties)
                return;
        }
 
-       if (!CE_STATIC_MEMBERS(ce)) {
-               zend_class_init_statics(ce);
-       }
-
        array_init(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();
+       add_class_vars(ce, 1, return_value);
 }
 /* }}} */
 
diff --git a/ext/reflection/tests/bug79487.phpt b/ext/reflection/tests/bug79487.phpt
deleted file mode 100644 (file)
index 5185c98..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
---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"
-}