PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/Zend/tests/bug62991.php

http://github.com/facebook/hiphop-php
PHP | 33 lines | 27 code | 6 blank | 0 comment | 0 complexity | 752f15d675b96cce7c27d3be91c5fab3 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. function test( varray $array )
  3. {
  4. $closure = function() use ( $array ) {
  5. print_r( $array );
  6. yield "hi";
  7. };
  8. return $closure();
  9. }
  10. function test2( varray $array )
  11. {
  12. $closure = function() use ( $array ) {
  13. print_r( $array );
  14. yield "hi";
  15. };
  16. return $closure; // if you return the $closure and call it outside this function it works.
  17. }
  18. <<__EntryPoint>> function main(): void {
  19. $generator = test(varray[ 1, 2, 3 ] );
  20. foreach($generator as $something) {
  21. }
  22. $generator = test2(varray[ 1, 2, 3 ] );
  23. foreach($generator() as $something) {
  24. }
  25. $generator = test2(varray[ 1, 2, 3 ] );
  26. echo "okey\n";
  27. }