summaryrefslogtreecommitdiff
path: root/Zend/tests/generators/generator_method.phpt
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/tests/generators/generator_method.phpt')
-rw-r--r--Zend/tests/generators/generator_method.phpt29
1 files changed, 29 insertions, 0 deletions
diff --git a/Zend/tests/generators/generator_method.phpt b/Zend/tests/generators/generator_method.phpt
new file mode 100644
index 0000000000..b8196c171e
--- /dev/null
+++ b/Zend/tests/generators/generator_method.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Methods can be generators
+--FILE--
+<?php
+
+class Test implements IteratorAggregate {
+ protected $data;
+
+ public function __construct(array $data) {
+ $this->data = $data;
+ }
+
+ public function getIterator() {
+ 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"