Bug #55559 [Com]: ReflectionClass::getProperties() wrongly returns static properties
| From: | info at strictcoding dot co dot uk | Date: | Wed, 31 Aug 2011 23:40:56 +0000 |
| Subject: | Bug #55559 [Com]: ReflectionClass::getProperties() wrongly returns static properties | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-163210@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55559&edit=1
ID: 55559
Comment by: info at strictcoding dot co dot uk
Reported by: info at strictcoding dot co dot uk
Summary: ReflectionClass::getProperties() wrongly returns
static properties
Status: Open
Type: Bug
Package: Reflection related
Operating System: Fedora 15
PHP Version: 5.3SVN-2011-08-31 (SVN)
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2011-08-31 22:28:57] 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 22:14:27] 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
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55559&edit=1