for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Bdf\Serializer\PropertyAccessor;
use ReflectionProperty;
/**
* ReflectionAccessor
*
* Use reflection to access object property
*/
class ReflectionAccessor implements PropertyAccessorInterface
{
* The class name
* @var string
private $class;
* The property name
private $property;
* The property reflection
* @var ReflectionProperty
private $reflection;
* Constructor
* @param string $class
* @param string $property
public function __construct(string $class, string $property)
$this->class = $class;
$this->property = $property;
$this->reflection = $this->createReflection();
}
* {@inheritdoc}
public function write($object, $value)
$this->reflection->setValue($object, $value);
public function read($object)
return $this->reflection->getValue($object);
* Create property accessor.
* @return ReflectionProperty
private function createReflection(): ReflectionProperty
$reflection = new ReflectionProperty($this->class, $this->property);
$reflection->setAccessible(true);
return $reflection;
* Dont serialize closures
* @return array
public function __sleep()
return ['class', 'property'];
* Rebuild reflection.
public function __wakeup()