letsdrink / ouzo

Ouzo Framework - PHP MVC ORM
https://github.com/letsdrink/ouzo
MIT License
70 stars 8 forks source link

Add a failing test for FluentArray.values() #292

Closed danon closed 3 years ago

danon commented 3 years ago

I recently found out that array_values() works differently for sequential and associative arrays.

I noticed that for some arrays array_values() resets internal array pointer, and for some it doesn't. Turns out, that array_values() only creates a new array if would be different. Sequential arrays would always be the same, so array_values() doesn't copy it, so the internal pointer is preserved.

I've written a failing unit test, you can see it's behaviour on the screen:

image

PS: What's funny, is that array_keys() and other methods don't have this behaviour, it's only array_values(). PS2: Perhaps apart from FluentArrays.values() also Arrays.values() could be added, which always returns a new array.

bbankowski commented 3 years ago

@Danon it should be merged to master, we do not use php8 branch anymore.