0
votes

I am working on a project based on Symfony 2.7.

I have added the following function a custom form type:

public function setDefaultOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(
      [
          'error_bubbling' => true
      ]
    );
}

... and when loading the form, I now get the following FatalErrorException:

Compile Error: Declaration of MyCompany\AppBundle\Form\ContactType::setDefaultOptions() must be compatible with Symfony\Component\Form\FormTypeInterface::setDefaultOptions(Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver)

Glancing at FormTypeInterface::setDefaultOptions(), it appears that I am complying with the method signature. What am I doing wrong?

1
Typehint OptionsResolverInterface is not the same as OptionsResolveru_mulder
Thanks to all of you. I tried Cid's answer, and it seems to have worked.Patrick

1 Answers

3
votes

You can either type $resolver correctly, it's expected to be OptionsResolverInterface, not OptionsResolver.

Or, better to replace setDefaultOptions(OptionsResolverInterface $resolver) by configureOptions(OptionsResolver $resolver) since it's deprecated in Symfony 2.7 source

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(
        [
            'error_bubbling' => true
        ]
    );
}