问题
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;
}
}
回答1:
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.
回答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.
来源:https://stackoverflow.com/questions/18735149/cannot-instantiate-abstract-class-in-appdevdebugprojectcontainer-php-symfo