PHP Fatal error: I'm trying to implement Form \ AbstractType in my Symfony2 application

I get the following error:

Fatal error: Declaration of Bean\OauthServerBundle\Form\Type\AuthorizeFormType::buildForm() must be compatible with Symfony\Component\Form\FormTypeInterface::buildForm(Symfony\Component\Form\FormBuilderInterface $builder, array $options) in src/Bean/OauthServerBundle/Form/Type/AuthorizeFormType.php on line 25 

I don’t know why I get this error. AbstractType :: buildForm () accepts FormBuilderInterface, and Symfony2 implements FormBuilderInterface for FormBuilder.

Here is the contents of my source:

 <?php namespace Bean\OauthServerBundle\Form\Type; use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\AbstractType; class AuthorizeFormType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { /* some code ... */ } /* more code ... */ } 
+8
php namespaces symfony
source share
2 answers

FormBuilderInterface and Symfony2 implements FormBuilderInterface for FormBuilder.

This does not change the fact that buildForm must be declared as in the parent class and accept any object that implements FormBuilderInterface .

+10
source share

So, the code from the symfony book should look like this:

 namespace Bean\OauthServerBundle\Form\Type; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\AbstractType; class AuthorizeFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { /* some code ... */ } /* more code ... */ } 

Is that what you mean?

+9
source share

All Articles