Skip to content
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

Harden check for numeric array indices #16908

Merged
merged 1 commit into from Dec 10, 2020
Merged

Harden check for numeric array indices #16908

merged 1 commit into from Dec 10, 2020

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Dec 8, 2020

Description:

Some of the tests actually had results that are not fully correct.

This peace of code actually returns true on PHP7 while it returns false on PHP 8:

$array = ['a' => 'b'];

return array_keys($array) == array_keys(array_fill(0, count($array), true)); // ['a'] == [0]

Comparing with === instead should have the same result on both versions.

If I understand the code correct it tries to check for default numeric indices. Comparing with === requires the keys to be of the same type and in the same order. Imho that should be correct as an array with shuffled order should imho not be handled as having default indices.

refs #16897

Review

  • Functional review done
  • Usability review done (is anything maybe unclear or think about anything that would cause people to reach out to support)
  • Security review done see checklist
  • Code review done
  • Tests were added if useful/possible
  • Reviewed for breaking changes
  • Developer changelog updated if needed
  • Documentation added if needed
  • Existing documentation updated if needed

@sgiehl sgiehl added the Needs Review PRs that need a code review label Dec 8, 2020
@sgiehl sgiehl added this to the 4.1.0 milestone Dec 8, 2020
@diosmosis diosmosis merged commit 6403a86 into 4.x-dev Dec 10, 2020
@diosmosis diosmosis deleted the fixarraycmp branch December 10, 2020 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants