[PropertyPath] Fixed usage of __get() and __set() when accessing properties that exist in the object but are not public
This commit is contained in:
parent
b4c359357f
commit
f73b6b4e1c
@ -318,13 +318,16 @@ class PropertyPath implements \IteratorAggregate
|
||||
}
|
||||
|
||||
return $object->$isser();
|
||||
} else if ($reflClass->hasMethod('__get')) {
|
||||
// needed to support magic method __get
|
||||
return $object->$property;
|
||||
} else if ($reflClass->hasProperty($property)) {
|
||||
if (!$reflClass->getProperty($property)->isPublic()) {
|
||||
throw new PropertyAccessDeniedException(sprintf('Property "%s" is not public in class "%s". Maybe you should create the method "get%s()" or "is%s()"?', $property, $reflClass->getName(), ucfirst($property), ucfirst($property)));
|
||||
}
|
||||
|
||||
return $object->$property;
|
||||
} else if (property_exists($object, $property) || $reflClass->hasMethod('__get')) {
|
||||
} else if (property_exists($object, $property)) {
|
||||
// needed to support \stdClass instances
|
||||
return $object->$property;
|
||||
} else {
|
||||
@ -361,13 +364,16 @@ class PropertyPath implements \IteratorAggregate
|
||||
}
|
||||
|
||||
$objectOrArray->$setter($value);
|
||||
} else if ($reflClass->hasMethod('__set')) {
|
||||
// needed to support magic method __set
|
||||
$objectOrArray->$property = $value;
|
||||
} else if ($reflClass->hasProperty($property)) {
|
||||
if (!$reflClass->getProperty($property)->isPublic()) {
|
||||
throw new PropertyAccessDeniedException(sprintf('Property "%s" is not public in class "%s". Maybe you should create the method "set%s()"?', $property, $reflClass->getName(), ucfirst($property)));
|
||||
}
|
||||
|
||||
$objectOrArray->$property = $value;
|
||||
} else if (property_exists($objectOrArray, $property) || $reflClass->hasMethod('__get')) {
|
||||
} else if (property_exists($objectOrArray, $property)) {
|
||||
// needed to support \stdClass instances
|
||||
$objectOrArray->$property = $value;
|
||||
} else {
|
||||
|
@ -4,15 +4,15 @@ namespace Symfony\Tests\Component\Form\Fixtures;
|
||||
|
||||
class Magician
|
||||
{
|
||||
private $properties = array();
|
||||
private $foobar;
|
||||
|
||||
public function __set($name, $value)
|
||||
public function __set($property, $value)
|
||||
{
|
||||
$this->properties[$name] = $value;
|
||||
$this->$property = $value;
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
public function __get($property)
|
||||
{
|
||||
return isset($this->properties[$name]) ? $this->properties[$name] : null;
|
||||
return isset($this->$property) ? $this->$property : null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user