|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-07-11 09:01 UTC] toycat at toycat dot eu
Description: ------------ The following is not a valid documentation (or there is a PHP bug): public mixed ReflectionProperty::getValue ( void ) --- From manual page: http://www.php.net/reflectionproperty.getvalue#refsect1- reflectionproperty.getvalue-description --- Test script: --------------- <?php class MyClass { public $property = 'test'; } $object = new MyClass(); $reflector = new \ReflectionObject($object); var_dump($reflector->getProperty('property')->getValue()); Expected result: ---------------- Outputs: string(4) "test" Actual result: -------------- Outputs: <br /> <b>Warning</b>: ReflectionProperty::getValue() expects exactly 1 parameter, 0 given in <b>__FILE__</b> on line <b>10</b><br /> NULL PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 05:00:01 2026 UTC |
The definition of the parameter states: If the property is non-static an object must be provided to fetch the property from. If you want to fetch the default property without providing an object use ReflectionClass::getDefaultProperties() instead. I believe that this functionality is accurately documented. <?php class MyClass { public $foo = 'test'; public static $bar = 'test'; } // Errors out $fooReflector = new ReflectionProperty('MyClass', 'foo'); var_dump($fooReflector->getValue()); // Works $staticReflector = new ReflectionProperty('MyClass', 'bar'); var_dump($staticReflector->getValue()); // Works because an instance of the object is passed in var_dump($fooReflector->getValue(new MyClass())); // Returns array('bar' => 'test', 'foo' => 'test') $classReflector = new ReflectionClass('MyClass'); var_dump($classReflector->getDefaultProperties());