]> granicus.if.org Git - php/commitdiff
MFH: fix #39067 (getDeclaringClass() and private properties)
authorAntony Dovgal <tony2001@php.net>
Fri, 6 Oct 2006 17:35:32 +0000 (17:35 +0000)
committerAntony Dovgal <tony2001@php.net>
Fri, 6 Oct 2006 17:35:32 +0000 (17:35 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/bug39067.phpt [new file with mode: 0644]

index a733a6a2f3b06591c8993d7f46d66ca3d8452f7b..280f63518848361c32c7ef0c5688f9905069cd1c 100644 (file)
@@ -4029,6 +4029,10 @@ ZEND_METHOD(reflection_property, getDeclaringClass)
        while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, prop_name, prop_name_len + 1, (void **) &tmp_info) == SUCCESS) {
                ce = tmp_ce;
                tmp_ce = tmp_ce->parent;
+               if (tmp_info->flags & ZEND_ACC_PRIVATE) {
+                       /* it's a private property, so it can't be inherited */
+                       break;
+               }
        }
 
        zend_reflection_class_factory(ce, return_value TSRMLS_CC);
diff --git a/ext/reflection/tests/bug39067.phpt b/ext/reflection/tests/bug39067.phpt
new file mode 100644 (file)
index 0000000..a3bf2ad
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+Bug #39067 (getDeclaringClass() and private properties)
+--FILE--
+<?php
+
+class A {
+       private $x;
+}
+
+class B extends A {
+       private $x;
+}
+
+class C extends B {
+       private $x;
+}
+
+$rc = new ReflectionClass('C');
+var_dump($rc->getProperty('x')->getDeclaringClass()->getName());
+
+$rc = new ReflectionClass('B');
+var_dump($rc->getProperty('x')->getDeclaringClass()->getName());
+
+$rc = new ReflectionClass('A');
+var_dump($rc->getProperty('x')->getDeclaringClass()->getName());
+
+echo "Done\n";
+?>
+--EXPECTF--    
+string(1) "C"
+string(1) "B"
+string(1) "A"
+Done