note 115705 added to language.generators.syntax
| From: | christophe dot maymard at gmail dot com | Date: | Thu, 11 Sep 2014 16:43:50 +0000 |
| Subject: | note 115705 added to language.generators.syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200416@lists.php.net to get a copy of this message | ||
<?php
//Example of class implementing IteratorAggregate using generator
class ValueCollection implements IteratorAggregate
{
private $items = array();
public function addValue($item)
{
$this->items[] = $item;
return $this;
}
public function getIterator()
{
foreach ($this->items as $item) {
yield $item;
}
}
}
//Initializes a collection
$collection = new ValueCollection();
$collection
->addValue('A string')
->addValue(new stdClass())
->addValue(NULL);
foreach ($collection as $item) {
var_dump($item);
}
----
Server IP: 72.52.91.14
Probable Submitter: 2a01:e35:8af3:a420:1d41:25ff:21d5:e0fc
----
Manual Page -- http://php.net/manual/en/language.generators.syntax.php
Edit -- https://master.php.net/note/edit/115705
Del: integrated -- https://master.php.net/note/delete/115705/integrated
Del: useless -- https://master.php.net/note/delete/115705/useless
Del: bad code -- https://master.php.net/note/delete/115705/bad+code
Del: spam -- https://master.php.net/note/delete/115705/spam
Del: non-english -- https://master.php.net/note/delete/115705/non-english
Del: in docs -- https://master.php.net/note/delete/115705/in+docs
Del: other reasons-- https://master.php.net/note/delete/115705
Reject -- https://master.php.net/note/reject/115705
Search -- https://master.php.net/manage/user-notes.php