The following could be used to write private / protected properties without reflection. Could be faster.
<?php
final class Guard
{
private $x = 'test';
}
$guard = new Guard();
$thief = function ($name)
{
return $this->$name;
};
$hydrator = function ($name, $value) {
$this->$name = $value;
};
echo $thief->bindTo($guard, Guard::class)('x') . "\n";
$hydrator->bindTo($guard, Guard::class)('x', 'bla');
echo $thief->bindTo($guard, Guard::class)('x') . "\n";
The following could be used to write private / protected properties without reflection. Could be faster.
https://3v4l.org/GqaLf
See https://ocramius.github.io/blog/accessing-private-php-class-members-without-reflection/