for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Happyr\SerializerBundle\PropertyManager;
/**
* An easy way to get properties from an object.
*
* @author Tobias Nyholm <[email protected]>
*/
class ReflectionPropertyAccess
{
* @param $object
* @param $propertyName
* @param $value
public static function set($object, $propertyName, $value)
$reflectionProperty = self::getReflectionProperty($object, $propertyName);
$reflectionProperty->setValue($object, $value);
}
* @return mixed
public static function get($object, $propertyName)
return $reflectionProperty->getValue($object);
* @return \ReflectionProperty
private static function getReflectionProperty($object, $propertyName)
$reflectionClass = new \ReflectionClass($object);
$reflectionProperty = $reflectionClass->getProperty($propertyName);
$reflectionProperty->setAccessible(true);
return $reflectionProperty;