Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Fatal error: I'm trying to implement a 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

Not sure why I'm getting this Error. AbstractType::buildForm() takes a FormBuilderInterface, and Symfony2 implements FormBuilderInterface for FormBuilder.

Here's the content 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 ... */
}
like image 961
Reza S Avatar asked Jul 28 '12 20:07

Reza S


2 Answers

FormBuilderInterface, and Symfony2 implements FormBuilderInterface for FormBuilder.

That doesn't change the fact, that buildForm has to be declared as in parent class and accept any object that implements FormBuilderInterface.

like image 196
dev-null-dweller Avatar answered Nov 02 '22 11:11

dev-null-dweller


So the code from 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 this what you mean?

like image 20
Decebal Avatar answered Nov 02 '22 10:11

Decebal