php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55559 ReflectionClass::getProperties() wrongly returns static properties
Submitted: 2011-08-31 22:14 UTC Modified: 2011-09-15 15:54 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: info at strictcoding dot co dot uk Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.3SVN-2011-08-31 (SVN) OS: Fedora 15
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: info at strictcoding dot co dot uk
New email:
PHP Version: OS:

 

 [2011-08-31 22:14 UTC] info at strictcoding dot co dot uk
Description:
------------
When used without ReflectionProperty::IS_STATIC, ReflectionClass::getProperties() 
still returns static properties.

Test script:
---------------
class A {
    public static $x;
}

$r = new ReflectionClass('A');
print_r($r->getProperties(ReflectionProperty::IS_PUBLIC));

Expected result:
----------------
Array
(
)

Actual result:
--------------
Array
(
    [0] => ReflectionProperty Object
        (
            [name] => x
            [class] => A
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-31 22:28 UTC] johannes@php.net
A static property is also a public property. I can see where you are coming from but I'm not sure I want to follow the logic. Maybe we'd need "negative" filters, while this makes it quite complex so I'd then again prefer filtering it from the outside.

As then you really have all the freedom.

   $non_private_properties = array_filter($r->getProperties(), function ($p) { return !$p->isPublic(); });
 [2011-08-31 23:40 UTC] info at strictcoding dot co dot uk
I can see your point, however what would be the purpose of IS_STATIC then?
The whole point of the filter parameter, IMO, is to ask for a property which 
either IS_PUBLIC, or IS_PUBLIC *and* IS_STATIC.
 [2011-09-15 15:54 UTC] iliaa@php.net
-Status: Open +Status: Bogus
 [2011-09-15 15:54 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The purpose would be to allow you to retrieve only the static properties, no bug 
here.
 [2012-07-28 00:51 UTC] no at mailinator dot com
uh, no, this *is* a bug. those flags are being logically OR'd with each other 
and are supposed to act as *filters*. consider the following:

i want to find a file with permissions "------rw-" (read/write access for public 
only). lets say i have these flags to work with:

OWNER_READ
OWNER_WRITE
OWNER_EXECUTE
GROUP_READ
GROUP_WRITE
GROUP_EXECUTE
PUBLIC_READ
PUBLIC_WRITE
PUBLIC_EXECUTE

i should only have to specify (PUBLIC_READ | PUBLIC_WRITE) to match "------rw-" 
*exactly*. well, according to you, owner and group members also belong to the 
public, so they should be implicitly included, and the search will match "rw-rw-
rw". what?

this is a bug.
 [2012-07-28 01:58 UTC] no at mailinator dot com
clarification:
(OWNER_READ|OWNER_WRITE) would match "------rw-"
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun May 26 07:01:26 2019 UTC