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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Sat Dec 21 14:01:32 2024 UTC