To allow protected and private properties to be accessed, you should use
ReflectionProperty::setAccessible(bool $accessible):
<?php
class Foo {
protected $bar = 'barrr!';
private $baz = 'bazzz!';
}
$reflFoo = new ReflectionClass('Foo');
$reflBar = $reflFoo->getProperty('bar');
$reflBaz = $reflFoo->getProperty('baz');
$reflBar->setAccessible(true);
$reflBaz->setAccessible(true);
$foo = new Foo();
echo $reflBar->getValue($foo); echo $reflBaz->getValue($foo); $reflBar->setValue($foo, "new value");
echo $reflBar->getValue($foo); ?>