1
votes

I'm getting the following error on Symfony2:

Warning: array_replace() [function.array-replace]: Argument #1 is not an array in /home/rackelas/public_html/dev/Symfony/vendor/symfony/src/Symfony/Component/Form/FormFactory.php line 236

after adding the following to Acme/Bundle/Form/Type/ContactType.php for validation:

public function getDefaultOptions(array $options)
{
    $collectionConstraint = new Collection(array(
        'name' => new MinLength(5),
        'email' => new Email(array('message' => 'Invalid email address')),
    ));

    $options['validation_constraint'] = $collectionConstraint;
}

source: http://symfony.com/doc/current/book/forms.html#using-a-form-without-a-class

Any help in the right direction would be appreciated.

2
Could you install XDebug? It would give you a full stack trace instead of just an error on one line.greg0ire
I'm not sure how to do that but I'll give it a google search, maybe it will help the next time around. Thanks.drack

2 Answers

4
votes

Try adding a return $options; to your getDefaultOptions method.

2
votes

What you are receiving is not an error, it is a warning.

The warning states that the function is looking for an array, but you are passing it a non-array variable.

So FormFactory.php on line 236 is calling array_replace() with an argument that is not an array. That is where you should be looking to resolve this problem.