grifix/reflection

该软件包已被 弃用 且不再维护。未建议替代包。

ReflectionObject 的包装器

维护者

详细信息

gitlab.com/grifix/reflection

1.0.1 2022-07-23 06:05 UTC

This package is auto-updated.

Last update: 2023-07-26 07:07:03 UTC


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