diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 0ad79f70c7..a159aea6cc 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -340,12 +340,8 @@ class Form implements \IteratorAggregate, FormInterface if (!empty($clientData)) { $dataClass = $this->config->getDataClass(); - if (null === $dataClass && is_object($clientData)) { - $expectedType = 'scalar'; - - if (count($this->children) > 0 && $this->config->getDataMapper()) { - $expectedType = 'array'; - } + if (null === $dataClass && is_object($clientData) && !$clientData instanceof \ArrayAccess) { + $expectedType = 'scalar, array or an instance of \ArrayAccess'; throw new FormException( 'The form\'s client data is expected to be of type ' . $expectedType . ', ' . diff --git a/src/Symfony/Component/Form/Tests/FormTest.php b/src/Symfony/Component/Form/Tests/FormTest.php index a15c9d6a40..389d5b4747 100644 --- a/src/Symfony/Component/Form/Tests/FormTest.php +++ b/src/Symfony/Component/Form/Tests/FormTest.php @@ -1249,6 +1249,21 @@ class FormTest extends \PHPUnit_Framework_TestCase $form->setData('foo'); } + public function testClientDataMayBeArrayAccessIfDataClassIsNull() + { + $arrayAccess = $this->getMock('\ArrayAccess'); + $config = new FormConfig('name', null, $this->dispatcher); + $config->appendClientTransformer(new FixedDataTransformer(array( + '' => '', + 'foo' => $arrayAccess, + ))); + $form = new Form($config); + + $form->setData('foo'); + + $this->assertSame($arrayAccess, $form->getClientData()); + } + /** * @expectedException Symfony\Component\Form\Exception\FormException */