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