|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48336 ReflectionProperty::getDeclaringClass() does not work with redeclared propertie
Submitted: 2009-05-19 20:19 UTC Modified: 2009-05-21 16:55 UTC
From: Markus dot Lidel at shadowconnect dot com Assigned:
Status: Closed Package: Reflection related
PHP Version: 5.3CVS-2009-05-19 (snap) OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: Markus dot Lidel at shadowconnect dot com
New email:
PHP Version: OS:


 [2009-05-19 20:19 UTC] Markus dot Lidel at shadowconnect dot com
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 @@
                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:

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');
  } catch(Exception $e) {

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-21 16:05 UTC]
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
Thank you for the report, and for helping us make PHP better.

 [2009-05-21 16:55 UTC] Markus dot Lidel at shadowconnect dot com
Thank you very much, with the latest snapshot everything works fine!
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 13:01:27 2024 UTC