#48336 [Opn->Csd]: ReflectionProperty::getDeclaringClass() does not work with redeclared propertie
| From: | lbarnaud@php.net | Date: | Thu, 21 May 2009 16:05:21 +0000 |
| Subject: | #48336 [Opn->Csd]: ReflectionProperty::getDeclaringClass() does not work with redeclared propertie | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-137613@lists.php.net to get a copy of this message | ||
ID: 48336
Updated by: lbarnaud@php.net
Reported By: Markus dot Lidel at shadowconnect dot com
-Status: Open
+Status: Closed
Bug Type: Reflection related
Operating System: Linux
PHP Version: 5.3CVS-2009-05-19 (snap)
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2009-05-19 20:19:06] Markus dot Lidel at shadowconnect dot com
Description:
------------
This is a duplicate of BUG #48286 because there is no way to reopen it
and i don't know if someone sees my last comments on this bug. The
ReflectionProperty::getDeclaringClass() does report wrong class in
derived classes. Always the first occurence of protected and public
properties is returned and not the class from which the property gets
its value. This is true with static and nonstatic properties.
This patch fixes the issue:
--- php_reflection.c.ori 2008-12-31 12:17:42.000000000 +0100
+++ php_reflection.c 2009-05-15 02:04:51.000000000 +0200
@@ -4125,6 +4125,10 @@
break;
}
ce = tmp_ce;
+ if (ce == tmp_info->ce) {
+ /* it's a redeclared property, so no further
inheritance needed */
+ break;
+ }
tmp_ce = tmp_ce->parent;
}
Reproduce code:
---------------
<?php
class A {
}
class B extends A {
static protected $prop;
}
class C extends B {
static protected $prop;
}
class D extends C {
}
class E extends D {
}
class F extends E {
static protected $prop;
}
$class = 'A';
for($class = 'A'; $class <= 'F'; $class ++) {
print($class.' => ');
try {
$rp = new ReflectionProperty($class, 'prop');
print($rp->getDeclaringClass()->getName());
} catch(Exception $e) {
print('N/A');
}
print("\n");
}
?>
Expected result:
----------------
A => N/A
B => B
C => C
D => C
E => C
F => F
Actual result:
--------------
A => N/A
B => B
C => B
D => B
E => B
F => B
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48336&edit=1