Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Config] Error accessing uninitialized $resolver in Loader #57066

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

Closed
radar3301 opened this issue May 22, 2024 · 2 comments
Closed

[Config] Error accessing uninitialized $resolver in Loader #57066

radar3301 opened this issue May 22, 2024 · 2 comments

Comments

@radar3301
Copy link
Contributor

radar3301 commented May 22, 2024

Symfony version(s) affected

6.x, 7.x

Description

I am receiving the following error:

Error {#2549
  #message: "Typed property Symfony\Component\Config\Loader\Loader::$resolver must not be accessed before initialization"
  #code: 0
  #file: "D:\inetroot\websites\demo\vendor\symfony\config\Loader\Loader.php"
  #line: 60
}

The line in question is: $loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type);, however, the defined property is protected LoaderResolverInterface $resolver; (line 35).

How to reproduce

class MyBundle extends AbstractBundle
{
    public function configure(DefinitionConfigurator $definition): void
    {
        $definition->import(dirname(__DIR__) . '/config/*.yaml', 'yaml');
    }
}

Please disregard the fact that I'm attempting to load YAML in the below reproduction code. Apparently there isn't built-in support for loading YAML configuration in bundles...

Possible Solution

I suggest the either of the following changes:

  1. Symfony 6.x / 7.x : $loader = isset($this->resolver) ? $this->resolver->resolve($resource, $type) : false;
  2. Symfony 7.x: protected ?LoaderResolverInterface $resolver and public function getResolver(): ?LoaderResolverInterface

Additional Context

No response

@radar3301
Copy link
Contributor Author

As an additional note, the following error also exists:

Fatal error: Uncaught TypeError: Symfony\Component\Config\Loader::getResolver(): Return value must be of type LoaderResolverInterface, null returned

@xabbuh
Copy link
Member

xabbuh commented May 23, 2024

see #57069

@fabpot fabpot closed this as completed May 25, 2024
fabpot added a commit that referenced this issue May 25, 2024
…xabbuh)

This PR was merged into the 7.0 branch.

Discussion
----------

[Config] gracefully handle cases when no resolver is set

| Q             | A
| ------------- | ---
| Branch?       | 7.0
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #57066
| License       | MIT

Commits
-------

aefeb67 gracefully handle cases when no resolver is set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants