Bug #53119 [Opn->Ver]: LimitIterator(ArrayIterator)->seek() doesn't work correctly after OutOfBoundsE

From: Date: Fri, 13 Aug 2021 14:36:38 +0000
Subject: Bug #53119 [Opn->Ver]: LimitIterator(ArrayIterator)->seek() doesn't work correctly after OutOfBoundsE
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235805@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=53119&edit=1 ID: 53119 Updated by: cmb@php.net Reported by: marc-bennewitz at arcor dot de Summary: LimitIterator(ArrayIterator)->seek() doesn't work correctly after OutOfBoundsE -Status: Open +Status: Verified Type: Bug Package: SPL related Operating System: Linux PHP Version: 5.3.3 Block user comment: N Private report: N New Comment: Interestingly, calling ::rewind() instead of ::seek(0) works as one would expect: <https://3v4l.org/PT2qW>. Previous Comments: ------------------------------------------------------------------------ [2018-08-18 13:56:12] cmb@php.net > With php < 5.3 it works as expected. Actually, with PHP < 5.2.14 and PHP < 5.3.3, respectively[1]. The behavioral change appears to have been introduced by fixing bug #49723. [1] <https://3v4l.org/9DrgU> ------------------------------------------------------------------------ [2010-10-21 18:22:10] marc-bennewitz at arcor dot de The LimitIterator should have the same behavior as the inner iterator (in this example ArrayIterator) but on ArrayIterator there is no need to call rewind after an Exception. ------------------------------------------------------------------------ [2010-10-21 11:50:29] johannes@php.net The exception leaves the iterator in undefined behavior. That is expected. ------------------------------------------------------------------------ [2010-10-20 20:47:02] marc-bennewitz at arcor dot de Description: ------------ Seeking after an OutOfBoundException doesn't work without call of rewind. With php < 5.3 it works as expected. Test script: --------------- $it = new ArrayIterator(array('zf9396', 'foo', null)); $it->rewind(); try { $it->seek(3); } catch (OutOfBoundsException $e) { var_dump($it->key()); $it->seek(0); var_dump($it->key()); } $lit = new LimitIterator($it, 0, 10); try { $lit->seek(3); } catch (OutOfBoundsException $e) { var_dump($lit->key()); $lit->seek(0); var_dump($lit->key()); } Expected result: ---------------- NULL int(0) NULL int(0) Actual result: -------------- NULL int(0) NULL NULL ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=53119&edit=1

« previous php.bugs (#235805) next »