Skip to content

[VarExporter][FrameworkBundle][7.0] Error when using a lazy AbstractController #52753

Closed
@keulinho

Description

@keulinho

Symfony version(s) affected

7.0

Description

For 7.0 the protected $container property was typed as ContainerInterface, this leads to an error when using it together with the LazyGhost as it tries to access the property before it is initialized.

How to reproduce

Extend the AbstractController, configure it in the container as lazy and with the setContainer method

Possible Solution

Catch the exception, and set null as fallback:
Before:

        $previous = $this->container ?? null;

After:

        try {
            $previous = $this->container;
        } catch (\Error) {
            $previous = null;
        }

I tried to use isset instead of null coalesce, but that leads to memory issues, so i guess catching the exception would be best

Additional Context

See stack trace:

Error: Cannot access uninitialized non-nullable property Symfony\Bundle\FrameworkBundle\Controller\AbstractController::$container by reference
/builds/shopware/6/product/platform/vendor/symfony/var-exporter/LazyGhostTrait.php:133
/builds/shopware/6/product/platform/vendor/symfony/framework-bundle/Controller/AbstractController.php:63
/builds/shopware/6/product/platform/var/cache/test_h8458ab63ca9647a85b0d42ef842db976/ContainerMg28vrx/Shopware_Core_KernelTestDebugContainer.php:2851
/builds/shopware/6/product/platform/var/cache/test_h8458ab63ca9647a85b0d42ef842db976/ContainerMg28vrx/Shopware_Core_KernelTestDebugContainer.php:2846
/builds/shopware/6/product/platform/vendor/symfony/var-exporter/Internal/LazyObjectState.php:61
/builds/shopware/6/product/platform/vendor/symfony/var-exporter/LazyGhostTrait.php:206
/builds/shopware/6/product/platform/vendor/symfony/framework-bundle/Controller/AbstractController.php:63
/builds/shopware/6/product/platform/vendor/symfony/framework-bundle/Controller/ControllerResolver.php:28
/builds/shopware/6/product/platform/vendor/symfony/http-kernel/Controller/ControllerResolver.php:66

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions