]> granicus.if.org Git - php/commitdiff
- MFB: Fixed bug #45139 (ReflectionProperty returns incorrect declaring class)
authorFelipe Pena <felipe@php.net>
Sun, 1 Jun 2008 03:13:54 +0000 (03:13 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 1 Jun 2008 03:13:54 +0000 (03:13 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/bug45139.phpt [new file with mode: 0644]

index afb7a565def56390b8c42ac68eb5075813ff36d5..305533c4f45e25c0c320dc29115d5f7f34c25878 100644 (file)
@@ -4202,7 +4202,7 @@ ZEND_METHOD(reflection_property, getDeclaringClass)
        prop_name_len = USTR_LEN(prop_name);
        ce = tmp_ce = ref->ce;
        while (tmp_ce && zend_u_hash_find(&tmp_ce->properties_info, UG(unicode)?IS_UNICODE:IS_STRING, prop_name, prop_name_len + 1, (void **) &tmp_info) == SUCCESS) {
-               if (tmp_info->flags & ZEND_ACC_PRIVATE) {
+               if (tmp_info->flags & ZEND_ACC_PRIVATE || tmp_info->flags & ZEND_ACC_SHADOW) {
                        /* it's a private property, so it can't be inherited */
                        break;
                }
diff --git a/ext/reflection/tests/bug45139.phpt b/ext/reflection/tests/bug45139.phpt
new file mode 100644 (file)
index 0000000..1c0507e
--- /dev/null
@@ -0,0 +1,58 @@
+--TEST--
+Bug #45139 (ReflectionProperty returns incorrect declaring class)
+--FILE--
+<?php
+
+class A {
+       private $foo;
+}
+
+class B extends A {
+       protected $bar;
+       private $baz;
+       private $quux;
+}
+
+class C extends B {
+       public $foo;
+       private $baz;
+       protected $quux;
+}
+
+$rc = new ReflectionClass('C');
+$rp = $rc->getProperty('foo');
+var_dump($rp->getDeclaringClass()->getName()); // c
+
+$rc = new ReflectionClass('A');
+$rp = $rc->getProperty('foo');
+var_dump($rp->getDeclaringClass()->getName()); // A
+
+$rc = new ReflectionClass('B');
+$rp = $rc->getProperty('bar');
+var_dump($rp->getDeclaringClass()->getName()); // B
+
+$rc = new ReflectionClass('C');
+$rp = $rc->getProperty('bar');
+var_dump($rp->getDeclaringClass()->getName()); // B
+
+$rc = new ReflectionClass('C');
+$rp = $rc->getProperty('baz');
+var_dump($rp->getDeclaringClass()->getName()); // C
+
+$rc = new ReflectionClass('B');
+$rp = $rc->getProperty('baz');
+var_dump($rp->getDeclaringClass()->getName()); // B
+
+$rc = new ReflectionClass('C');
+$rp = $rc->getProperty('quux');
+var_dump($rp->getDeclaringClass()->getName()); // C
+
+?>
+--EXPECT--
+unicode(1) "C"
+unicode(1) "A"
+unicode(1) "B"
+unicode(1) "B"
+unicode(1) "C"
+unicode(1) "B"
+unicode(1) "C"