4

I have just installed yesterday apc and I am now getting this error:

FatalErrorException: Error: Cannot instantiate abstract class
ACME\WebBundle\Menu\MenuBuilder in
/var/www/app/cache/dev/appDevDebugProjectContainer.php line 743

and in that line there is:

protected function getEposMain_MenuBuilderService()
{
    return $this->services['epos_main.menu_builder'] = new \ACME\WebBundle\Menu\MenuBuilder($this->get('knp_menu.factory'));
}

Does any one know what does it mean and what I can do with it?

services.yml

services:
    epos_main.menu_builder:
        class: ACME\WebBundle\Menu\MenuBuilder
        arguments: ["@knp_menu.factory"]

    epos_main.menu.main:
        class: Knp\Menu\MenuItem # the service definition requires setting the class
        factory_service: epos_main.menu_builder
        factory_method: createMainMenu
        arguments:
            - @request
            - @twig
            - 'ACMEWebBundle:Menu:menu.html.twig'
        scope: request # needed as we have the request as a dependency here
        tags:
            - { name: knp_menu.menu, alias: main } # The alias is what is used to retrieve the menu

    epos.twig.epos_extension:
        class: ACME\WebBundle\Twig\ePOSTwigExtension
        tags:
            - { name: twig.extension }

a bit of MenuBuilder Class code:

namespace ACME\WebBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\HttpFoundation\Request;

class MenuBuilder
{
    private $factory;

    /**
     * @param FactoryInterface $factory
     */
    public function __construct(FactoryInterface $factory)
    {
        $this->factory = $factory;
    }

    public function createMainMenu(Request $request)
    {

        $menu = $this->factory->createItem('root');
        $menu->setChildrenAttribute('class', 'nav');
        ...
        ...
        return $menu;
    }
}
3
  • Have you tried to clear the cache? Commented Sep 11, 2013 at 7:34
  • Check your services.yml It looks like you declared your service as non abstract whilst it is. Did you forget to add a factory ? Commented Sep 11, 2013 at 7:35
  • The problem is this that everything was working fine and I haven't change anything in that services.yml and in that class. I have edited my question with adding code from services.yml and a bit code of a MenuBuilder class. Commented Sep 11, 2013 at 8:39

2 Answers 2

12

Well the error is pretty self-explanatory. You cannot instantiate an Abstract Class as per OOP rules !

Your MenuBuilder is an abstract class and you are trying to instantiate with a new keyword which is not possible.

Sign up to request clarification or add additional context in comments.

1 Comment

How can you tell if a class is abstract? he did not declare it abstract in its definition... I am currently stuck in a similar problem.
2

If your MenuBuilder class was abstract at some point and you changed it to be a concrete class, it's possible that APC still has the old version lurking around (in memory).

Try restarting your webserver.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.