php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63582 ReflectionClass->getProperties() omits private members of parent classes
Submitted: 2012-11-22 16:12 UTC Modified: 2012-11-24 14:56 UTC
From: anthon dot pang at gmail dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.5.0alpha1 OS: Ubuntu 12.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
44 - 26 = ?
Subscribe to this entry?

 
 [2012-11-22 16:12 UTC] anthon dot pang at gmail dot com
Description:
------------
getProperties() doesn't include "private" scoped properties from parent classes

Test script:
---------------
<?php
abstract class Foo {
    public  $a;
    protected $b;
    private $c;
}

class Bar extends Foo {
    public $d;
    protected $e;
    private $f;
}

$obj = new Bar;
$reflection = new ReflectionClass($obj);
$propertyList = $reflection->getProperties();

foreach ($propertyList as $property) {
    var_dump($property->getName());
}

Expected result:
----------------
string(1) "d"
string(1) "e"
string(1) "f"
string(1) "a"
string(1) "b"
string(1) "c"

Actual result:
--------------
string(1) "d"
string(1) "e"
string(1) "f"
string(1) "a"
string(1) "b"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-23 01:54 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2012-11-23 01:54 UTC] aharvey@php.net
Private properties and methods only exist within the exact class they are defined in: note that if you call getParentClass() on the $reflection object and then call getProperties() on that, "c" appears along with the other properties defined in Foo.
 [2012-11-24 14:56 UTC] anthon dot pang at gmail dot com
Thanks for the explanation.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC