1
0
mirror of https://github.com/php/php-src.git synced 2026-04-24 00:18:23 +02:00

Properly handle yield during method calls

This commit is contained in:
Nikita Popov
2012-06-03 02:16:29 +02:00
parent 7b3bfa5784
commit bf82f46ea9
2 changed files with 43 additions and 0 deletions
@@ -0,0 +1,35 @@
--TEST--
Yield can be used during a method call
--FILE--
<?php
class A {
public function b($c) {
echo $c, "\n";
}
}
function *gen() {
$a = new A;
$a->b(yield);
}
$gen = gen();
$gen->send('foo');
// test resource cleanup
$gen = gen();
$gen->rewind();
$gen->close();
// test cloning
$g1 = gen();
$g1->rewind();
$g2 = clone $g1;
$g1->close();
$g2->send('bar');
?>
--EXPECT--
foo
bar
+8
View File
@@ -41,6 +41,10 @@ void zend_generator_close(zend_generator *generator, zend_bool finished_executio
zval_ptr_dtor(&execute_data->current_this);
}
if (execute_data->object) {
zval_ptr_dtor(&execute_data->object);
}
/* If the generator is closed before it can finish execution (reach
* a return statement) we have to free loop variables manually, as
* we don't know whether the SWITCH_FREE / FREE opcodes have run */
@@ -228,6 +232,10 @@ static void zend_generator_clone_storage(zend_generator *orig, zend_generator **
);
Z_ADDREF_P(clone->send_target->var.ptr);
}
if (execute_data->object) {
Z_ADDREF_P(execute_data->object);
}
}
/* The value and key are known not to be references, so simply add refs */