]> granicus.if.org Git - php/commitdiff
https://bugs.php.net/bug.php?id=64979
authorMarcel Araujo <ceceldada@gmail.com>
Fri, 21 Jun 2013 21:25:51 +0000 (18:25 -0300)
committerStanislav Malyshev <stas@php.net>
Sun, 18 Aug 2013 22:09:43 +0000 (15:09 -0700)
Zend/tests/generators/generator_closure_static_variable.phpt [new file with mode: 0644]

diff --git a/Zend/tests/generators/generator_closure_static_variable.phpt b/Zend/tests/generators/generator_closure_static_variable.phpt
new file mode 100644 (file)
index 0000000..01d7240
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Closures with static variables can be generators
+--FILE--
+<?php
+
+function new_closure_gen() {
+       return function() { 
+               static $foo = 0; 
+               yield ++$foo; 
+       };
+}
+
+$closure1 = new_closure_gen();
+$closure2 = new_closure_gen();
+
+$gen1 = $closure1();
+$gen2 = $closure1();
+$gen3 = $closure2();
+
+foreach (array($gen1, $gen2, $gen3) as $gen) {
+  foreach ($gen as $val) {
+    print "$val\n";
+  }
+}
+
+?>
+--EXPECT--
+int(1)
+int(2)
+int(1)
\ No newline at end of file