Skip to content

[HttpKernel] Uninitialized property in the abstract Bundle class #52436

@javiereguiluz

Description

@javiereguiluz

Symfony version(s) affected

7.0

Description

In a Symfony bundle (https://github.com/symfonycorp/connect) we have this:

namespace SymfonyCorp\Connect;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class SymfonyConnectBundle extends Bundle
{
    public function getContainerExtension(): ?ExtensionInterface
    {
        if (null === $this->extension) {
            $this->extension = new SymfonyConnectExtension();
        }

        return $this->extension;
    }

    // ...
}

It works fine in all Symfony versions up to and including 6.4.

But, in 7.0 (beta2) we're seeing this error:

Typed property Symfony\Component\HttpKernel\Bundle\Bundle::$extension
must not be accessed before initialization.

The error happens because this line in 6.4:

Turned into this line in 7.0:

protected ExtensionInterface|false $extension;

If I make this change in Symfony code, everything works again:

-protected ExtensionInterface|false $extension;
+protected ExtensionInterface|false|null $extension = null;

So, what should we do here? Thanks!

How to reproduce

Use this bundle https://github.com/symfonycorp/connect in a Symfony 7 application.

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy