Skip to content

[DI] Cleanup array_key_exists #19689

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 2 commits into from
Closed

[DI] Cleanup array_key_exists #19689

wants to merge 2 commits into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Aug 21, 2016

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)

@nicolas-grekas
Copy link
Member

I tend to think this could theoretically be OK , BUT practically I don't see any reasons to take the risk of breaking something given that the existing array_key_exists checks don't hurt performance nor anything else.
Thus 👎

@ro0NL
Copy link
Contributor Author

ro0NL commented Aug 22, 2016

What would we break? Only null is affected.. we shouldnt consider people actually relying on this quirk from our side. Imo.

@ro0NL
Copy link
Contributor Author

ro0NL commented Aug 22, 2016

Not cleaning up out of fear.. or not knowing about intention of code is 👎 for me.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Aug 22, 2016

we shouldnt consider people actually relying on this quirk from our side.

That's where our opinions diverge. By experience, people do use extension points to do clever things we can't imagine beforehand.

@ro0NL
Copy link
Contributor Author

ro0NL commented Aug 22, 2016

Understand, and i know this is difficult. My point is, this was not intended/designed to be a extension point at all. We make it really hard for ourselves also this way.

This should be considered rationally, do we intend array_key_exists or not. Im really curious about that...

My opionion:

  • whatever the user is doing with $this->services, doesnt matter
  • has is designed to return true when set (hence isset)

@nicolas-grekas
Copy link
Member

Re-read, removing my 👎
Should be on 2.7 btw.

@ro0NL
Copy link
Contributor Author

ro0NL commented Aug 22, 2016

Rebased. Diff is the same :-) I cant edit the base branch on github i guess?

@stof
Copy link
Member

stof commented Aug 22, 2016

@ro0NL you can edit it (they deployed this feature 1 week ago)

@ro0NL ro0NL changed the base branch from master to 2.7 August 22, 2016 14:13
@ro0NL
Copy link
Contributor Author

ro0NL commented Aug 22, 2016

Made my day. Thanks @stof

@nicolas-grekas
Copy link
Member

👍 :)
Status: reviewed

@stof
Copy link
Member

stof commented Aug 22, 2016

👍

@fabpot
Copy link
Member

fabpot commented Aug 22, 2016

Indeed, null was a significant value before #8582, but it's not anymore.

@fabpot
Copy link
Member

fabpot commented Aug 22, 2016

Thank you @ro0NL.

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
@fabpot fabpot closed this Aug 22, 2016
@ro0NL ro0NL deleted the di/cleanup-array-key-exists branch August 22, 2016 15:54
@dmaicher
Copy link
Contributor

dmaicher commented Sep 4, 2016

This seems to be causing some BC breaks 😢

#19840

@nicolas-grekas
Copy link
Member

See #19847

nicolas-grekas added a commit to nicolas-grekas/symfony that referenced this pull request Sep 4, 2016
This reverts commit c89f80a, reversing
changes made to 386e5e7.
nicolas-grekas added a commit that referenced this pull request Sep 6, 2016
…" (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

Revert "minor #19689 [DI] Cleanup array_key_exists (ro0NL)"

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| Tests pass?   | yes
| Fixed tickets | #19689 #19840 #19825 #19857
| License       | MIT
| Doc PR        | -

This reverts commit c89f80a, reversing
changes made to 386e5e7.

See discussion in #19847

I'll try adding test cases soon that ensure that:

- [x] *when not leaving scope* synthetic services always throw and ignore the `ContainerInterface::NULL_ON_INVALID_REFERENCE` flag (on 3.x also)
- [x] *when leaving scope* synthetic services always return null and ignore the `ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE`  (until 2.8 since scopes are gone in 3.x)

Commits
-------

8cb28bf [DI] Add anti-regression test
ac742df Revert "minor #19689 [DI] Cleanup array_key_exists (ro0NL)"
nicolas-grekas added a commit that referenced this pull request Sep 6, 2016
* 2.7:
  [FrameworkBundle] Check for class existence before is_subclass_of
  Update GroupSequence.php
  Code enhancement and cleanup
  [DI] Add anti-regression test
  Revert "minor #19689 [DI] Cleanup array_key_exists (ro0NL)"
  [BrowserKit] Fix cookie expiration on 32 bit systems
  bumped Symfony version to 2.7.18
  updated VERSION for 2.7.17
  update CONTRIBUTORS for 2.7.17
  updated CHANGELOG for 2.7.17
  Update misleading comment about RFC4627
nicolas-grekas added a commit that referenced this pull request Sep 6, 2016
* 2.8:
  [FrameworkBundle] Check for class existence before is_subclass_of
  Update GroupSequence.php
  Code enhancement and cleanup
  [Form] Fix transformer tests after the ICU update
  [DI] Add anti-regression test
  Revert "minor #19689 [DI] Cleanup array_key_exists (ro0NL)"
  bumped Symfony version to 2.8.11
  updated VERSION for 2.8.10
  updated CHANGELOG for 2.8.10
  [BrowserKit] Fix cookie expiration on 32 bit systems
  bumped Symfony version to 2.7.18
  updated VERSION for 2.7.17
  update CONTRIBUTORS for 2.7.17
  updated CHANGELOG for 2.7.17
  Update misleading comment about RFC4627
nicolas-grekas added a commit that referenced this pull request Sep 6, 2016
* 3.1:
  [FrameworkBundle] Check for class existence before is_subclass_of
  Update GroupSequence.php
  Code enhancement and cleanup
  [Form] Fix transformer tests after the ICU update
  [DI] Add anti-regression test
  Revert "minor #19689 [DI] Cleanup array_key_exists (ro0NL)"
  bumped Symfony version to 3.1.5
  updated VERSION for 3.1.4
  updated CHANGELOG for 3.1.4
  bumped Symfony version to 2.8.11
  updated VERSION for 2.8.10
  updated CHANGELOG for 2.8.10
  [BrowserKit] Fix cookie expiration on 32 bit systems
  bumped Symfony version to 2.7.18
  updated VERSION for 2.7.17
  update CONTRIBUTORS for 2.7.17
  updated CHANGELOG for 2.7.17
  Update misleading comment about RFC4627
@nicolas-grekas
Copy link
Member

Reverted on 2.7 & 2.8, kept on 3.*

This was referenced Sep 7, 2016
@ro0NL
Copy link
Contributor Author

ro0NL commented Sep 7, 2016

@nicolas-grekas @fabpot sorry for this :-)

@fabpot fabpot mentioned this pull request Oct 3, 2016
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 2.7:
  [FrameworkBundle] Check for class existence before is_subclass_of
  Update GroupSequence.php
  Code enhancement and cleanup
  [DI] Add anti-regression test
  Revert "minor symfony#19689 [DI] Cleanup array_key_exists (ro0NL)"
  [BrowserKit] Fix cookie expiration on 32 bit systems
  bumped Symfony version to 2.7.18
  updated VERSION for 2.7.17
  update CONTRIBUTORS for 2.7.17
  updated CHANGELOG for 2.7.17
  Update misleading comment about RFC4627
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 2.8:
  [FrameworkBundle] Check for class existence before is_subclass_of
  Update GroupSequence.php
  Code enhancement and cleanup
  [Form] Fix transformer tests after the ICU update
  [DI] Add anti-regression test
  Revert "minor symfony#19689 [DI] Cleanup array_key_exists (ro0NL)"
  bumped Symfony version to 2.8.11
  updated VERSION for 2.8.10
  updated CHANGELOG for 2.8.10
  [BrowserKit] Fix cookie expiration on 32 bit systems
  bumped Symfony version to 2.7.18
  updated VERSION for 2.7.17
  update CONTRIBUTORS for 2.7.17
  updated CHANGELOG for 2.7.17
  Update misleading comment about RFC4627
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 3.1:
  [FrameworkBundle] Check for class existence before is_subclass_of
  Update GroupSequence.php
  Code enhancement and cleanup
  [Form] Fix transformer tests after the ICU update
  [DI] Add anti-regression test
  Revert "minor symfony#19689 [DI] Cleanup array_key_exists (ro0NL)"
  bumped Symfony version to 3.1.5
  updated VERSION for 3.1.4
  updated CHANGELOG for 3.1.4
  bumped Symfony version to 2.8.11
  updated VERSION for 2.8.10
  updated CHANGELOG for 2.8.10
  [BrowserKit] Fix cookie expiration on 32 bit systems
  bumped Symfony version to 2.7.18
  updated VERSION for 2.7.17
  update CONTRIBUTORS for 2.7.17
  updated CHANGELOG for 2.7.17
  Update misleading comment about RFC4627
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants