<?php
class AAA {
private $a = '777';
function __toString() {
return \sprintf("%s\n", $this->a);
}
}
$a = new AAA;
echo $a;
$b = new ReflectionClass(AAA::class);
$property = $b->getProperty('a');
$property->setAccessible(true);
$property->setValue($a, 999);
echo $a;
as@avs:~$ php7.1 /tmp/testReflection.php
777
999