grifix / reflection
该软件包已被 弃用 且不再维护。未建议替代包。
ReflectionObject 的包装器
1.0.1
2022-07-23 06:05 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpunit/phpunit: ^9.5
README
composer install grifix/reflection
使用方法
final class Car
{
public function __construct(public string $producer, public Engine $engine)
{
}
}
final class Engine
{
public function __construct(public int $volume)
{
}
}
$car = new Car('Mercedes', new Engine(5));
$reflection = new \Grifix\Reflection\ReflectionObject($car);
$reflection->getPropertyValue('producer'); //Mercedes
$reflection->getPropertyValue('engine.volume'); //5
$reflection->setPropertyValue('producer', 'Volvo');
$reflection->setPropertyValue('engine.volume', 10);
$reflection->getObject(); //Car
$reflection->getWrapped(); //\ReflectionObject