From fba1e9d0c5c34b60b63b97e2605ce430186c17e1 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 1 Jun 2008 03:08:59 +0000 Subject: [PATCH] - Fixed bug #45139 (ReflectionProperty returns incorrect declaring class) --- NEWS | 1 + ext/reflection/php_reflection.c | 2 +- ext/reflection/tests/bug45139.phpt | 58 ++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 ext/reflection/tests/bug45139.phpt diff --git a/NEWS b/NEWS index 5e45a65f94..2fb1f95ad3 100644 --- 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) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 845ab3ec0d..f210261022 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -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 index 0000000000..6aa84263c6 --- /dev/null +++ b/ext/reflection/tests/bug45139.phpt @@ -0,0 +1,58 @@ +--TEST-- +Bug #45139 (ReflectionProperty returns incorrect declaring class) +--FILE-- +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" -- 2.50.1