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

diff --git a/NEWS b/NEWS
index 5e45a65f94efde5f591637a9fbf5269e44428292..2fb1f95ad35e44217101c92f3c3247174ef72f8a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2008, PHP 5.2.7
+- Fixed bug #45139 (ReflectionProperty returns incorrect declaring class). (Felipe)
 - When dumping entire document to file via asXml() don't lose the encoding.
   (Ilia)
 - Fixed a crash inside PDO when trying instantiate PDORow manually (Felipe)
index 845ab3ec0dd7c61a0e23b5b0af91df2d3d85e51e..f2102610227dd0ff4e34af761b14e0739f3050c7 100644 (file)
@@ -4081,7 +4081,7 @@ ZEND_METHOD(reflection_property, getDeclaringClass)
        prop_name_len = strlen(prop_name);
        ce = tmp_ce = ref->ce;
        while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, 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..6aa8426
--- /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--
+string(1) "C"
+string(1) "A"
+string(1) "B"
+string(1) "B"
+string(1) "C"
+string(1) "B"
+string(1) "C"