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

FluentArray.skip() and limit() leak array_slice() implementation detail #297

Open
danon opened this issue Apr 27, 2022 · 0 comments
Open

Comments

@danon
Copy link
Member

danon commented Apr 27, 2022

If you run this

$array = [
    'Key' => 'One',
    10    => 'Two',
    20    => 'Three'
];
//when
$result = FluentArray::from($array)->limit(2)->toArray();

The resulting array is ['Key' => 'One', 0 => 'Two'], which doesn't make any sense. Same for skip(). (array_slice() reindexes integer keys, but keeps string keys -.-)

What should be done now is:

  • limit() and skip() should preserve keys (add true flag to array_slice()) - this probably makes more sense
  • limit() and skip() should reindex the array (use array_values())
@danon danon changed the title FluentArray.skip() and limit() leaks array_slice() implementation detail FluentArray.skip() and limit() leak array_slice() implementation detail May 2, 2022
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

No branches or pull requests

1 participant