Bug #76852 [Opn->Nab]: IteratorIterator doesn't initialize without being rewound

From: Date: Sat, 08 Sep 2018 23:48:05 +0000
Subject: Bug #76852 [Opn->Nab]: IteratorIterator doesn't initialize without being rewound
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216937@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76852&edit=1 ID: 76852 Updated by: requinix@php.net Reported by: morozov at tut dot by Summary: IteratorIterator doesn't initialize without being rewound -Status: Open +Status: Not a bug Type: Bug Package: SPL related Operating System: Linux PHP Version: 7.2.9 Block user comment: N Private report: N New Comment: ArrayIterator may be usable immediately but that is not true for all iterators. IteratorIterator starts in an invalid state because the inner iterator may have as well. Always call rewind() before using *any* iterator. Previous Comments: ------------------------------------------------------------------------ [2018-09-08 22:04:32] morozov at tut dot by Description: ------------ Right after construction, the state of IteratorIterator doesn't reflect the state of the underlying iterator. Despite the fact that the underlying iterator is valid and has non-empty values of key and value, the wrapper is invalid and hass NULL values of key and value. Test script: --------------- $it = new ArrayIterator([1, 2, 3]); var_dump($it->valid()); var_dump($it->key()); var_dump($it->current()); $it = new IteratorIterator($it); var_dump($it->valid()); var_dump($it->key()); var_dump($it->current()); Expected result: ---------------- bool(true) int(0) int(1) bool(true) int(0) int(1) Actual result: -------------- bool(true) int(0) int(1) bool(false) NULL NULL ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76852&edit=1

« previous php.bugs (#216937) next »