@ 2015-11-23T16:09:45Z <?php
class Foo {
public static $staticProperty = 'foobar';
public $property = 'barfoo';
private $privateProperty = 'foofoo';
}
$reflectionClass = new ReflectionClass('Foo');
var_dump($reflectionClass->getProperty('staticProperty')->getValue());
var_dump($reflectionClass->getProperty('property')->getValue(new Foo));
$reflectionProperty = $reflectionClass->getProperty('privateProperty');
$reflectionProperty->setAccessible(true);
var_dump($reflectionProperty->getValue());
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.27 , 8.2.0 - 8.2.17 , 8.3.0 - 8.3.4 string(6) "foobar"
string(6) "barfoo"
Fatal error: Uncaught TypeError: ReflectionProperty::getValue(): Argument #1 ($object) must be provided for instance properties in /in/ECoZr:17
Stack trace:
#0 /in/ECoZr(17): ReflectionProperty->getValue()
#1 {main}
thrown in /in/ECoZr on line 17
Process exited with code 255 . Output for 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.10 , 7.2.0 - 7.2.33 , 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 string(6) "foobar"
string(6) "barfoo"
Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 0 given in /in/ECoZr on line 17
NULL
preferences:dark mode live preview
143.65 ms | 403 KiB | 177 Q