note 90715 added to class.iterator
| From: | mike dot thornton at firstroi dot com | Date: | Tue, 05 May 2009 20:40:32 +0000 |
| Subject: | note 90715 added to class.iterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-154262@lists.php.net to get a copy of this message | ||
It's important to note that following won't work if you have null values.
<?php
function valid() {
var_dump(__METHOD__);
return isset($this->array[$this->position]);
}
?>
Other examples have shown the following which won't work if you have false values:
<?php
function valid() {
return $this->current() !== false;
}
?>
Instead use:
<?php
function valid() {
return array_key_exists($this->array, $this->position);
}
?>
Or the following if you do not store the position.
<?php
public function valid() {
return !is_null(key($this->array));
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 65.46.136.234
----
Manual Page -- http://www.php.net/manual/en/class.iterator.php
Edit -- https://master.php.net/note/edit/90715
Del: integrated -- https://master.php.net/note/delete/90715/integrated
Del: useless -- https://master.php.net/note/delete/90715/useless
Del: bad code -- https://master.php.net/note/delete/90715/bad+code
Del: spam -- https://master.php.net/note/delete/90715/spam
Del: non-english -- https://master.php.net/note/delete/90715/non-english
Del: in docs -- https://master.php.net/note/delete/90715/in+docs
Del: other reasons-- https://master.php.net/note/delete/90715
Reject -- https://master.php.net/note/reject/90715
Search -- https://master.php.net/manage/user-notes.php