Commit: 40760ecb90d1b024c76862e33d13d40137650af7 Author: Nikita Popov <ni...@php.net> Sun, 3 Jun 2012 02:40:03 +0200 Parents: bf82f46ea9028faa3830525d2462effe7d08600d Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=40760ecb90d1b024c76862e33d13d40137650af7 Log: Fix cloning of generator methods Forgot to add a reference to the this variable Changed paths: A Zend/tests/generators/clone_with_this.phpt M Zend/zend_generators.c Diff: diff --git a/Zend/tests/generators/clone_with_this.phpt b/Zend/tests/generators/clone_with_this.phpt new file mode 100644 index 0000000..b0f28be --- /dev/null +++ b/Zend/tests/generators/clone_with_this.phpt @@ -0,0 +1,24 @@ +--TEST-- +Cloning a generator method (with this) +--FILE-- +<?php + +class Test { + protected $foo; + + public function *gen() { + $this->foo = 'bar'; + yield; // interrupt + var_dump($this->foo); + } +} + +$g1 = (new Test)->gen(); +$g1->rewind(); // goto yield +$g2 = clone $g1; +$g1->close(); +$g2->next(); + +?> +--EXPECT-- +string(3) "bar" diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index a3277e6..b5642dd 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -233,6 +233,10 @@ static void zend_generator_clone_storage(zend_generator *orig, zend_generator ** Z_ADDREF_P(clone->send_target->var.ptr); } + if (execute_data->current_this) { + Z_ADDREF_P(execute_data->current_this); + } + if (execute_data->object) { Z_ADDREF_P(execute_data->object); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php