Bug #69238 [Nab]: getProperties() Doesn't list undeclared class properties

From: Date: Sun, 15 Mar 2015 02:25:03 +0000
Subject: Bug #69238 [Nab]: getProperties() Doesn't list undeclared class properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191393@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69238&edit=1 ID: 69238 User updated by: geolim4 at gmail dot com Reported by: geolim4 at gmail dot com Summary: getProperties() Doesn't list undeclared class properties Status: Not a bug Type: Bug Package: Reflection related Operating System: Debian 3.2.65-1+deb7u1 x86_64 PHP Version: 5.6.6 Block user comment: N Private report: N New Comment: Indeed, i missed it. But now i realize that getProperties() still have a bug, why does when i loop on $properties and i check call getValue() on each property, this method returns the DYNAMIC value and not the declared value. As you said that's Class related and not object related. Previous Comments: ------------------------------------------------------------------------ [2015-03-15 02:14:47] reeze@php.net You need use ReflectionObject instead of ReflectionClass, since dynamic properties is not part of Class ------------------------------------------------------------------------ [2015-03-15 02:14:05] geolim4 at gmail dot com In that case the method name has a nonsense, the method should be named getDeclaredProperties() instead. Or an insufficiently completed docbook. But in that case, why the value returned is the dynamic value, and not declared value? I don't get it. If it's an excepted behavior, it must be explicitly mentioned in the docbook. ------------------------------------------------------------------------ [2015-03-15 02:06:35] laruence@php.net I think it's not a bug but a expected behavior, the baz is a dynamic property of a instance of class Foo ------------------------------------------------------------------------ [2015-03-14 23:46:43] geolim4 at gmail dot com As you can see the test was done inside a namespace, the bug is also reproduced in global scope. ------------------------------------------------------------------------ [2015-03-14 23:44:59] geolim4 at gmail dot com Description: ------------ It seem that ReflectionClass::getProperties() doesn't fetch undeclared properties of an object, even if you specify all the filters such ReflectionProperty::IS_xxxxxx Test script: --------------- class foo { public $bar = false; private $foobar = false; function __construct() { $this->bar = false; $this->foobar = true; $this->baz = true; } } $data = new foo(); $class = new \ReflectionClass($data); $properties = $class->getProperties(); \var_dump( $properties ); exit; Expected result: ---------------- array(2) { [0]=> &object(ReflectionProperty)#3 (2) { ["name"]=> string(3) "bar" ["class"]=> string(3) "foo" } [1]=> &object(ReflectionProperty)#4 (2) { ["name"]=> string(6) "foobar" ["class"]=> string(3) "foo" } [2]=> &object(ReflectionProperty)#4 (2) { ["name"]=> string(6) "baz" ["class"]=> string(3) "foo" } } Actual result: -------------- array(2) { [0]=> &object(ReflectionProperty)#3 (2) { ["name"]=> string(3) "bar" ["class"]=> string(3) "foo" } [1]=> &object(ReflectionProperty)#4 (2) { ["name"]=> string(6) "foobar" ["class"]=> string(3) "foo" } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69238&edit=1

« previous php.bugs (#191393) next »