-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Fixed unsetting from loosely equal keys OrderedHashMap #24566
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
maryo
commented
Oct 15, 2017
Q | A |
---|---|
Branch? | 2.7 |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #24558 |
License | MIT |
Thank you @maryo. |
…ryo) This PR was merged into the 2.7 branch. Discussion ---------- Fixed unsetting from loosely equal keys OrderedHashMap | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24558 | License | MIT Commits ------- ba37cba Fixed unsetting from loosely equal keys OrderedHashMap
@@ -144,7 +144,7 @@ public function offsetSet($key, $value) | |||
*/ | |||
public function offsetUnset($key) | |||
{ | |||
if (false !== ($position = array_search($key, $this->orderedKeys))) { | |||
if (false !== ($position = array_search((string) $key, $this->orderedKeys))) { |
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.
Wouldn't it have been enough to pass true
as the third argument here?
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.
@xabbuh https://3v4l.org/vBboa
When unsetting a numeric string offset like unset($map['1'])
, $key
equals to integer 1
. So it's needed to treat these numeric strings the same way as integers. Hence the cast. And since $this->orderedKeys
are all strings (the new cast in offsetSet
), passing true
would result in the same.