--- /dev/null
+--TEST--
+Bug #62991 (Segfault with generator and closure)
+--FILE--
+<?php
+
+function test( array $array )
+{
+ $closure = function() use ( $array ) {
+ print_r( $array );
+ yield "hi";
+ };
+ return $closure();
+}
+
+function test2( array $array )
+{
+ $closure = function() use ( $array ) {
+ print_r( $array );
+ yield "hi";
+ };
+ return $closure; // if you return the $closure and call it outside this function it works.
+}
+
+$generator = test(array( 1, 2, 3 ) );
+foreach($generator as $something) {
+}
+
+$generator = test2(array( 1, 2, 3 ) );
+foreach($generator() as $something) {
+}
+
+
+$generator = test2(array( 1, 2, 3 ) );
+
+echo "okey\n";
+?>
+--EXPECT--
+Array
+(
+ [0] => 1
+ [1] => 2
+ [2] => 3
+)
+Array
+(
+ [0] => 1
+ [1] => 2
+ [2] => 3
+)
+okey
efree(prev_execute_data);
}
+ /* Free a clone of closure */
+ if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
+ destroy_op_array(op_array TSRMLS_CC);
+ efree(op_array);
+ }
+
efree(execute_data);
generator->execute_data = NULL;
}
zval *return_value;
zend_generator *generator;
+ /* Create a clone of closure, because it may be destroyed */
+ if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
+ zend_op_array *op_array_copy = (zend_op_array*)emalloc(sizeof(zend_op_array));
+ *op_array_copy = *op_array;
+ function_add_ref(op_array_copy);
+ op_array = op_array_copy;
+ }
+
/* Create new execution context. We have to back up and restore
* EG(current_execute_data) and EG(opline_ptr) here because the function
* modifies it. */