mirror of
https://github.com/php/php-src.git
synced 2026-03-24 08:12:21 +01:00
30 lines
490 B
PHP
30 lines
490 B
PHP
--TEST--
|
|
Methods can be generators
|
|
--FILE--
|
|
<?php
|
|
|
|
class Test implements IteratorAggregate {
|
|
protected $data;
|
|
|
|
public function __construct(array $data) {
|
|
$this->data = $data;
|
|
}
|
|
|
|
public function getIterator(): Traversable {
|
|
foreach ($this->data as $value) {
|
|
yield $value;
|
|
}
|
|
}
|
|
}
|
|
|
|
$test = new Test(['foo', 'bar', 'baz']);
|
|
foreach ($test as $value) {
|
|
var_dump($value);
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
string(3) "foo"
|
|
string(3) "bar"
|
|
string(3) "baz"
|