Skip to content

Commit

Permalink
[PropertyPath] Fixed usage of __get() and __set() when accessing prop…
Browse files Browse the repository at this point in the history
…erties that exist in the object but are not public
  • Loading branch information
julesbou authored and fabpot committed Dec 10, 2010
1 parent b4c3593 commit f73b6b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/Symfony/Component/Form/PropertyPath.php
Expand Up @@ -318,13 +318,16 @@ protected function readProperty($object, $currentIndex)
}

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 {
Expand Down Expand Up @@ -361,13 +364,16 @@ protected function updateProperty(&$objectOrArray, $currentIndex, $value)
}

$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 {
Expand Down
10 changes: 5 additions & 5 deletions tests/Symfony/Tests/Component/Form/Fixtures/Magician.php
Expand Up @@ -4,15 +4,15 @@

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;
}
}

0 comments on commit f73b6b4

Please sign in to comment.