1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Files
archived-php-src/Zend/tests/generators/generator_method.phpt
Máté Kocsis 75a678a7e3 Declare tentative return types for Zend (#7251)
Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-07-19 13:44:20 +02:00

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"