doc-en icon indicating copy to clipboard operation
doc-en copied to clipboard

reset($arrayIterator) returns false

Open darckking opened this issue 4 years ago • 1 comments

From manual page: https://php.net/function.reset


Not sure if it's a bug or not but I didn't find mention about it in the Changelog. So, I call reset() with ArrayIterator argument and get false

$arrayIterator = new \ArrayIterator(['a', 'b']);
echo reset($arrayIterator); // prints nothing because it returns false

I use PHP 7.4.27 I tested this piece of code in PHP Sandbox with 7.3.25 and 7.2.31 - both versions return 'a' value.

Anyway, I'll refactor my code to avoid reset() with ArrayIterator argument.

darckking avatar Feb 02 '22 21:02 darckking

It is already stated for ArrayObject in the migration guide:

reset(), current(), etc. Use Iterator methods instead.

Probably makes sense to mention ArrayIterator here as well, and there should be respective changelog entries on the ArrayObject and ArrayIterator man pages.

cmb69 avatar Feb 03 '22 12:02 cmb69

This got clarified on the reset() page at one point, so closing. If someone considers this to still be an issue please open a new one.

Girgias avatar Jul 25 '23 16:07 Girgias