10000 [PHP 7.4 RC6] Anonymous class used in getContainerExtension causes: ReflectionException: Class "Configuration" not found while loading "\Configuration" · Issue #34613 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PHP 7.4 RC6] Anonymous class used in getContainerExtension causes: ReflectionException: Class "Configuration" not found while loading "\Configuration" #34613

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
ruudk opened this issue Nov 25, 2019 · 0 comments
Labels
Good first issue Ideal for your first contribution! (some Symfony experience may be required) Help wanted Issues and PRs which are looking for volunteers to complete them.

Comments

@ruudk
Copy link
Contributor
ruudk commented Nov 25, 2019

Symfony version(s) affected: 4.4.0

Description & How to reproduce
I'm running PHP 7.4 RC6 on CircleCI and discovered a weird error.

I'm using DoctrineDataFixturesExtension that defines it's extension using an anonymous class:
https://github.com/BehatExtension/DoctrineDataFixturesExtension/blob/0304b9df7037993cde56dbe38eef31b8d2717854/src/Bundle/BehatDoctrineDataFixturesExtensionBundle.php#L21-L26

When I run a unit test that uses KernelTestCase I get the following error:

ReflectionException: Class "Configuration" not found while loading "\Configuration".

vendor/symfony/config/Resource/ClassExistenceResource.php:150
vendor/symfony/config/Resource/ClassExistenceResource.php:78
vendor/symfony/dependency-injection/ContainerBuilder.php:353
vendor/symfony/dependency-injection/Extension/Extension.php:86
vendor/symfony/dependency-injection/Compiler/MergeExtensionConfigurationPass.php:68
vendor/symfony/http-kernel/DependencyInjection/MergeExtensionConfigurationPass.php:39
vendor/symfony/dependency-injection/Compiler/Compiler.php:94
vendor/symfony/dependency-injection/ContainerBuilder.php:762
vendor/symfony/http-kernel/Kernel.php:625
vendor/symfony/http-kernel/Kernel.php:136
vendor/symfony/framework-bundle/Test/KernelTestCase.php:79
tests/Domain/Command/DeserializableCommand.php:41

I think the problem is here:

public function getConfiguration(array $config, ContainerBuilder $container)
{
$class = \get_class($this);
$class = substr_replace($class, '\Configuration', strrpos($class, '\\'));
$class = $container->getReflectionClass($class);

I added some var_dump calls:

// line 83
string(161) "class@anonymous�vendor/behat-extension/doctrine-data-fixtures-extension/src/Bundle/BehatDoctrineDataFixturesExtensionBundle.php0x7f4f3938801a"

// line 84
string(14) "\Configuration"

I think this must be related to the anonymous class.

Is this even supported? And if it is, how should we handle this case properly?

Possible Solution
Would an early return like this help?

        $reflection = new \ReflectionClass($this);
        if ($reflection->isAnonymous()) {
            return null;
        }
ruudk added a commit to ruudk/DoctrineDataFixturesExtension that referenced this issue Nov 27, 2019
This doesn't work properly on PHP 7.4 for some reason.

symfony/symfony#34613
ruudk added a commit to ruudk/DoctrineDataFixturesExtension that referenced this issue Nov 27, 2019
This doesn't work properly on PHP 7.4 for some reason.

symfony/symfony#34613
Spomky pushed a commit to BehatExtension/DoctrineDataFixturesExtension that referenced this issue Nov 27, 2019
This doesn't work properly on PHP 7.4 for some reason.

symfony/symfony#34613
@nicolas-grekas nicolas-grekas added Help wanted Issues and PRs which are looking for volunteers to complete them. Good first issue Ideal for your first contribution! (some Symfony experience may be required) labels Nov 28, 2019
nicolas-grekas added a commit that referenced this issue Dec 19, 2019
…s is anonymous (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] skip looking for config class when the extension class is anonymous

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34613
| License       | MIT
| Doc PR        | -

Commits
-------

1c7eda4 [DI] skip looking for config class when the extension class is anonymous
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Ideal for your first contribution! (some Symfony experience may be required) Help wanted Issues and PRs which are looking for volunteers to complete them.
Projects
None yet
Development

No branches or pull requests

2 participants
0