|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-03-22 14:44 UTC] vlad dot turchinskiy at yandex dot ru
Description: ------------ Referencing to SplFixedArray interrupts foreach loop. Test script: --------------- https://3v4l.org/FdN4i Expected result: ---------------- 3 iterations executed. Actual result: -------------- 1 iteration executed. PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 15:00:01 2025 UTC |
Presuming for Iterators foreach ($it as $el) { var_dump($el); } is equivalent to for ($it->rewind(); $it->valid(); $it->next()) { $el = $it->current(); var_dump($el); } the behavior is correct. On the other hand, SplDoublyLinkedList, for instance, supports nested traversal via foreach ...Yes, a single foreach loop works certainly as expected; the problem is *nesting* of foreach loops: <?php $spl = SplFixedArray::fromArray([0, 1]); foreach ($spl as $el1) { foreach ($spl as $el2) { echo "$el1.$el2\n"; } } ?> outputs 0.0 0.1 while you want to get 0.0 0.1 1.0 1.1 It seems to me that this behavior is correct for Iterators; maybe not for IteratorAggregates.