From:             Markus dot Lidel at shadowconnect dot com
Operating system: Linux
PHP version:      5.3CVS-2009-05-19 (snap)
PHP Bug Type:     Reflection related
Bug description:  ReflectionProperty::getDeclaringClass() does not work with 
redeclared propertie

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 bug report at http://bugs.php.net/?id=48336&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=48336&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=48336&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=48336&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=48336&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=48336&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=48336&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=48336&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=48336&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=48336&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=48336&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=48336&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=48336&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=48336&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=48336&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48336&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48336&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=48336&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=48336&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=48336&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=48336&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=48336&r=mysqlcfg

Reply via email to