Permalink
Browse files

[Form] added support for stdClass objects

ReflectionClass doesn't list properties on stdClass objects (or objects cast
from arrays).  This allows these annoymous objects to be used as field data.
  • Loading branch information...
1 parent c3b89ee commit b2e4b452a43e1b82286b972960e806ffc3014deb Brandon Turner committed with fabpot Sep 24, 2010
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/Symfony/Component/Form/Field.php
@@ -573,6 +573,9 @@ protected function readProperty($object, PropertyPath $propertyPath)
}
return $object->$property;
+ } else if (property_exists($object, $property)) {
+ // needed to support \stdClass instances
+ return $object->$property;
} else {
throw new InvalidPropertyException(sprintf('Neither property "%s" nor method "%s()" nor method "%s()" exists in class "%s"', $property, $getter, $isser, $reflClass->getName()));
}
@@ -604,6 +607,9 @@ protected function updateProperty(&$objectOrArray, PropertyPath $propertyPath)
}
$objectOrArray->$property = $this->getData();
+ } else if (property_exists($objectOrArray, $property)) {
+ // needed to support \stdClass instances
+ $objectOrArray->$property = $this->getData();
} else {
throw new InvalidPropertyException(sprintf('Neither element "%s" nor method "%s()" exists in class "%s"', $property, $setter, $reflClass->getName()));
}

0 comments on commit b2e4b45

Please sign in to comment.