generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Description
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";
See https://ocramius.github.io/blog/accessing-private-php-class-members-without-reflection/
vjik