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

index 3d2045faa68d2c1c4e32963f69d86d79b8f12273..b3e97c69089b26a959ee7a49035295df88803d4c 100644 (file)
@@ -4101,6 +4101,10 @@ ZEND_METHOD(reflection_property, getDeclaringClass)
        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) {
                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..c225dc4
--- /dev/null
@@ -0,0 +1,38 @@
+--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
+--UEXPECTF--
+unicode(1) "C"
+unicode(1) "B"
+unicode(1) "A"
+Done