Skip to content

[DependencyInjection] Removed extra strtolower calls #14470

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
wants to merge 4 commits into from
Closed

[DependencyInjection] Removed extra strtolower calls #14470

wants to merge 4 commits into from

Conversation

dosten
Copy link
Contributor

@dosten dosten commented Apr 25, 2015

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Alias already lowercase the $id in the constructor. Using ContainerBuilder::hasAlias() and ContainerBuilder::hasDefinition() inside the code makes an extra strtolower call.

@@ -686,7 +686,7 @@ public function setAlias($alias, $id)
throw new InvalidArgumentException('$id must be a string, or an Alias object.');
}

if ($alias === strtolower($id)) {
if ($alias === $id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems wrong: string === Alias can never be true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, casted $id to a string and added a missing test for this condition.

@Tobion
Copy link
Contributor

Tobion commented Apr 25, 2015

get could be optimized this way as well with getDefinition and hasDefinition

@dosten
Copy link
Contributor Author

dosten commented Apr 25, 2015

@Tobion agree, btw you know the reason why in some hassers array_key_exists is used?

@Tobion
Copy link
Contributor

Tobion commented Apr 25, 2015

to support null
👍

@fabpot
Copy link
Member

fabpot commented Apr 27, 2015

Thank you @dosten.

fabpot added a commit that referenced this pull request Apr 27, 2015
…sten)

This PR was squashed before being merged into the 2.3 branch (closes #14470).

Discussion
----------

[DependencyInjection] Removed extra strtolower calls

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

`Alias` already lowercase the `$id` in the constructor. Using `ContainerBuilder::hasAlias()` and `ContainerBuilder::hasDefinition()` inside the code makes an extra strtolower call.

Commits
-------

3bfbf45 [DependencyInjection] Removed extra strtolower calls
@fabpot fabpot closed this Apr 27, 2015
@dosten dosten deleted the extra-strtolower branch April 27, 2015 13:11
fabpot added a commit that referenced this pull request Aug 22, 2016
This PR was squashed before being merged into the 2.7 branch (closes #19689).

Discussion
----------

[DI] Cleanup array_key_exists

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | comma-separated list of tickets fixed by the PR, if any
| License       | MIT
| Doc PR        | reference to the documentation PR, if any

Investigated this a bit, and to me it looks like left-over code. `null` doesnt end up in `$this->services` by design (this was done in #8582) so it seems. The test added then for regression still passes :)

I cant believe we guarantee BC for users doing `$this->services['id'] = null` (due protected), allowing them to break the design of `has`, `get` and `initialized` right now.

This also happens for `$this->definitions` in `ContainerBuilder`, maybe because `Container` did it alteady.. but im not sure.

Then again, there's this comment: #14470 (comment)

Commits
-------

3306c70 [DI] Cleanup array_key_exists
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.

3 participants