bug62991.phpt 787 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. --TEST--
  2. Bug #62991 (Segfault with generator and closure)
  3. --FILE--
  4. <?php
  5. function test( array $array )
  6. {
  7. $closure = function() use ( $array ) {
  8. print_r( $array );
  9. yield "hi";
  10. };
  11. return $closure();
  12. }
  13. function test2( array $array )
  14. {
  15. $closure = function() use ( $array ) {
  16. print_r( $array );
  17. yield "hi";
  18. };
  19. return $closure; // if you return the $closure and call it outside this function it works.
  20. }
  21. $generator = test(array( 1, 2, 3 ) );
  22. foreach($generator as $something) {
  23. }
  24. $generator = test2(array( 1, 2, 3 ) );
  25. foreach($generator() as $something) {
  26. }
  27. $generator = test2(array( 1, 2, 3 ) );
  28. echo "okey\n";
  29. ?>
  30. --EXPECT--
  31. Array
  32. (
  33. [0] => 1
  34. [1] => 2
  35. [2] => 3
  36. )
  37. Array
  38. (
  39. [0] => 1
  40. [1] => 2
  41. [2] => 3
  42. )
  43. okey