note 108609 added to class.iterator
| From: | fetidfrog at gmail dot com | Date: | Thu, 10 May 2012 15:11:06 +0000 |
| Subject: | note 108609 added to class.iterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187569@lists.php.net to get a copy of this message | ||
If you have a custom iterator that may throw an exception in it's current() method, there is no
way to catch the exception without breaking a foreach loop.
The following for loop allows you to skip elements for which $iterator->current() throws an
exception, rather than breaking the loop.
<?php
for ($iterator->rewind(); $iterator->valid(); $iterator->next()) {
try {
$value = $iterator->current();
} catch (Exception $exception) {
continue;
}
# ...
}
?>
----
Server IP: 94.76.225.145
Probable Submitter: 86.140.183.231
----
Manual Page -- http://www.php.net/manual/en/class.iterator.php
Edit -- https://master.php.net/note/edit/108609
Del: integrated -- https://master.php.net/note/delete/108609/integrated
Del: useless -- https://master.php.net/note/delete/108609/useless
Del: bad code -- https://master.php.net/note/delete/108609/bad+code
Del: spam -- https://master.php.net/note/delete/108609/spam
Del: non-english -- https://master.php.net/note/delete/108609/non-english
Del: in docs -- https://master.php.net/note/delete/108609/in+docs
Del: other reasons-- https://master.php.net/note/delete/108609
Reject -- https://master.php.net/note/reject/108609
Search -- https://master.php.net/manage/user-notes.php