-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Fix Cannot declare class ...\DefinitionDecorator, because the name is already in use #22657
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
Conversation
…me is already in use
Here is the fixed reproducer build on Travis: https://travis-ci.org/ogizanagi/symfony-21369/builds/229639096 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserving autocompletion as well 👍
Thank you @ogizanagi. |
…ause the name is already in use (ogizanagi) This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Fix Cannot declare class ...\DefinitionDecorator, because the name is already in use | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21369 | License | MIT | Doc PR | N/A The `return` trick doesn't seem to work, and php is still trying to declare the `DefinitionDecorator` class, which causes the "Cannot declare class ...\DefinitionDecorator, because the name is already in use" error because of the `class_alias` previously declared in `ChildDefinition.php`. This never happens as soon as the `ChildDefinition` class is used first, as the alias will take hand, but their are some situations, like in some unit test cases it can happen apparently, because `DefinitionDecorator` is used first. Commits ------- 530849e [DI] Fix Cannot declare class ...\DefinitionDecorator, because the name is already in use
Don't we have other places where we follow the same approach? |
@xabbuh : You probably mean the |
I guess it is actually, for the same reasons as here: composer classmap and the |
…sDecisionManager BC layer (ogizanagi) This PR was merged into the 3.3-dev branch. Discussion ---------- [Security] Fix TraceableAccessDecisionManager / DebugAccessDecisionManager BC layer | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22657 (comment) | License | MIT | Doc PR | N/A Same as #22657 for the renaming of `DebugAccessDecisionManager` into `TraceableAccessDecisionManager`. Indeed, I think we also require to redeclare the old `DebugAccessDecisionManager` for composer `classmap-authoritative` autoloading strategy & classmap dumper. AppVeyor failures unrelated. Edit: Re-thinking about it, it's probably not very common to dump the classmap and use the `classmap-authoritative` strategy when using those classes... That's to say: in debug mode/dev env. So it may be the reason why the class wasn't redeclared on contrary of `DefinitionDecorator`. Commits ------- 5b123b9 [Security] Fix TraceableAccessDecisionManager / DebugAccessDecisionManager BC layer
This PR was merged into the 1.x branch. Discussion ---------- Use class_exists instead of require I think this is required for symfony/symfony#23073 to pass. It's probably very similar to symfony/symfony#22657. A simple reproducer: ```php <?php use Twig\Node\Node; require_once __DIR__ . '/vendor/autoload.php'; new Node(); new \Twig_Node(); ``` [Without this patch](https://travis-ci.org/symfony/symfony/jobs/239712676#L2100): ```php PHP Fatal error: Cannot declare class Twig_Node, because the name is already in use in vendor/twig/twig/lib/Twig/Node.php on line 20 ``` With, everything works fine, whatever the two calls order. Commits ------- 2c174e4 Use class_exists instead of require
The
return
trick doesn't seem to work, and php is still trying to declare theDefinitionDecorator
class, which causes the "Cannot declare class ...\DefinitionDecorator, because the name is already in use" error because of theclass_alias
previously declared inChildDefinition.php
.This never happens as soon as the
ChildDefinition
class is used first, as the alias will take hand, but their are some situations, like in some unit test cases it can happen apparently, becauseDefinitionDecorator
is used first.