note 108657 added to language.oop5.iterations
| From: | jille at hexon dot cx | Date: | Tue, 15 May 2012 12:29:46 +0000 |
| Subject: | note 108657 added to language.oop5.iterations | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187988@lists.php.net to get a copy of this message | ||
Please note that if you implement your iterator this way instead of with an IteratorAggregate you
can not nest foreach-loops. This is because when the inner-loop is done the cursor is beyond the
last element, then the outer-loop asks for the next element and finds the cursor beyond the last
element as the innter-loop left it there.
<?php
// Wont work!
foreach($collection as $a) {
foreach($collection as $b) {
var_dump($a->someFunc($b));
}
}
?>
----
Server IP: 91.199.167.223
Probable Submitter: 82.93.241.107
----
Manual Page -- http://www.php.net/manual/en/language.oop5.iterations.php
Edit -- https://master.php.net/note/edit/108657
Del: integrated -- https://master.php.net/note/delete/108657/integrated
Del: useless -- https://master.php.net/note/delete/108657/useless
Del: bad code -- https://master.php.net/note/delete/108657/bad+code
Del: spam -- https://master.php.net/note/delete/108657/spam
Del: non-english -- https://master.php.net/note/delete/108657/non-english
Del: in docs -- https://master.php.net/note/delete/108657/in+docs
Del: other reasons-- https://master.php.net/note/delete/108657
Reject -- https://master.php.net/note/reject/108657
Search -- https://master.php.net/manage/user-notes.php