diff options
author | Felipe Pena <felipe@php.net> | 2008-06-01 03:11:38 +0000 |
---|---|---|
committer | Felipe Pena <felipe@php.net> | 2008-06-01 03:11:38 +0000 |
commit | 5050450f7938cfb4ddbcc63b28fae125ce74b83d (patch) | |
tree | 48f2ded2debf1c4adce2451c8ae374e1bea9538a | |
parent | 4c2e05a6e7b3123bfd05a26fe8126817f29cb3e8 (diff) | |
download | php-git-5050450f7938cfb4ddbcc63b28fae125ce74b83d.tar.gz |
- MFB: Fixed bug #45139 (ReflectionProperty returns incorrect declaring class)
-rw-r--r-- | ext/reflection/php_reflection.c | 2 | ||||
-rw-r--r-- | ext/reflection/tests/bug45139.phpt | 58 |
2 files changed, 59 insertions, 1 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index b077f7084d..8a671e130f 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4092,7 +4092,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 index 0000000000..6aa84263c6 --- /dev/null +++ b/ext/reflection/tests/bug45139.phpt @@ -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" |