Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to a member function has() on null #307

Open
shubaivan opened this issue Feb 2, 2018 · 6 comments
Open

Call to a member function has() on null #307

shubaivan opened this issue Feb 2, 2018 · 6 comments

Comments

@shubaivan
Copy link

shubaivan commented Feb 2, 2018

U use Symfony 3.3.10 and php 7.1. I install "jms/di-extra-bundle": "1.7.0" and after that have error

Call to a member function has() on null
vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php
line 356

my action

    public function getAdminQuestionAction(ParamFetcher $paramFetcher)
    {
        try {
            $em = $this->getDoctrine();

after when I called getDoctrine I have exception
and code where throw exception, line 356

    /**
     * Shortcut to return the Doctrine Registry service.
     *
     * @return Registry
     *
     * @throws \LogicException If DoctrineBundle is not available
     */
    protected function getDoctrine()
    {
        if (!$this->container->has('doctrine')) {
            throw new \LogicException('The DoctrineBundle is not registered in your application.');
        }

        return $this->container->get('doctrine');
    }
@zhil
Copy link

zhil commented Feb 4, 2018

related symfony2 issue symfony/symfony#23200

@zhil
Copy link

zhil commented Feb 4, 2018

this issue looks like duplicate of #282

@shubaivan
Copy link
Author

yes, it's true, I try "symfony/symfony": "~3.4", and "jms/di-extra-bundle": "~1.9" ad still have Call to a member function has() on null

@Aerendir
Copy link

Same issue here: completely disabling the bundle solves the problem...

And yes, the problem is a known one not already solved as pointed out by @zhil that referenced the issue #282 .

Unfortunately are almost 7 months this issue exist and it is not fixed.

On my side I'm required to use this bundle to use JMSTranslationBundle, but as it completely breaks my application, I think I will switch to PHPTranslation that also offer a Symfony's Bundle.

Good luck.

@shubaivan
Copy link
Author

thnks @Aerendir

    AppBundle\Controller\:
        resource: '../../src/AppBundle/Controller'
        public: true
        tags: ['controller.service_arguments']
        calls:
            - [setContainer, ["@service_container"]]

@rvanlaak
Copy link

rvanlaak commented May 31, 2018

@shubaivan the problem with adding that call for all resources, is that not all of the controllers in '../../src/AppBundle/Controller' might have the setContainer method.

In our case; 20% of the controllers are simple, easily autowirable callables and 80% are extending the base Controller class which means setContainer is available.

In other words, not sure if there is a generic solution for this. Maybe instantiateController could make use of the FrameworkBundle's ControllerResolver?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants