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

Skip to content

[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

Merged
merged 1 commit into from
May 7, 2017
Merged

[DI] Fix Cannot declare class ...\DefinitionDecorator, because the name is already in use #22657

merged 1 commit into from
May 7, 2017

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented May 7, 2017

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.

@ogizanagi
Copy link
Contributor Author

Here is the fixed reproducer build on Travis: https://travis-ci.org/ogizanagi/symfony-21369/builds/229639096

Copy link
Member

@chalasr chalasr left a 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 👍

@fabpot
Copy link
Member

fabpot commented May 7, 2017

Thank you @ogizanagi.

@fabpot fabpot merged commit 530849e into symfony:master May 7, 2017
fabpot added a commit that referenced this pull request May 7, 2017
…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
@ogizanagi ogizanagi deleted the fix/3.3/child_def_bc_layer branch May 7, 2017 15:22
@xabbuh
Copy link
Member

xabbuh commented May 7, 2017

Don't we have other places where we follow the same approach?

@ogizanagi
Copy link
Contributor Author

ogizanagi commented May 7, 2017

@xabbuh : You probably mean the TraceableAccessDecisionManagerand DebugAccessDecisionManager. Actually we did not try to redeclare the DebugAccessDecisionManager class in DebugAccessDecisionManager.php on the contrary of the DefinitionDecorator in this PR. Do you think we missed it, or is it not required?

@ogizanagi
Copy link
Contributor Author

I guess it is actually, for the same reasons as here: composer classmap and the classmap-authoritative strategy. See #22664.

fabpot added a commit that referenced this pull request May 11, 2017
…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
@fabpot fabpot mentioned this pull request May 17, 2017
fabpot added a commit to twigphp/Twig that referenced this pull request Jun 5, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants