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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: anthon dot pang at gmail dot com
New email:
PHP Version: OS:

 

 [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-2020 The PHP Group
All rights reserved.
Last updated: Sun Mar 29 13:01:26 2020 UTC