Commit: bcc7d976f31a572160a52c15f415deea3497ab68 Author: Nikita Popov <ni...@php.net> Mon, 28 May 2012 00:24:58 +0200 Parents: 9f52c5c22647f0648dbb350c551417b1ad070359 Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=bcc7d976f31a572160a52c15f415deea3497ab68 Log: Set EG(current_execute_data) This fixes several issues. In particular it makes method generators work properly and also allows generators using a symbol table. Changed paths: A Zend/tests/generators/generator_method.phpt M Zend/zend_generators.c Diff: diff --git a/Zend/tests/generators/generator_method.phpt b/Zend/tests/generators/generator_method.phpt new file mode 100644 index 0000000..b64476d --- /dev/null +++ b/Zend/tests/generators/generator_method.phpt @@ -0,0 +1,29 @@ +--TEST-- +Methods can be generators +--FILE-- +<?php + +class Test implements IteratorAggregate { + protected $data; + + public function __construct(array $data) { + $this->data = $data; + } + + public function *getIterator() { + foreach ($this->data as $value) { + yield $value; + } + } +} + +$test = new Test(['foo', 'bar', 'baz']); +foreach ($test as $value) { + var_dump($value); +} + +?> +--EXPECT-- +string(3) "foo" +string(3) "bar" +string(3) "baz" diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index 12116a0..00d637c 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -148,6 +148,7 @@ static void zend_generator_resume(zval *object, zend_generator *generator TSRMLS { /* Backup executor globals */ zval **original_return_value_ptr_ptr = EG(return_value_ptr_ptr); + zend_execute_data *original_execute_data = EG(current_execute_data); zend_op **original_opline_ptr = EG(opline_ptr); zend_op_array *original_active_op_array = EG(active_op_array); HashTable *original_active_symbol_table = EG(active_symbol_table); @@ -160,6 +161,7 @@ static void zend_generator_resume(zval *object, zend_generator *generator TSRMLS EG(return_value_ptr_ptr) = &object; /* Set executor globals */ + EG(current_execute_data) = generator->execute_data; EG(opline_ptr) = &generator->execute_data->opline; EG(active_op_array) = generator->execute_data->op_array; EG(active_symbol_table) = generator->execute_data->symbol_table; @@ -175,6 +177,7 @@ static void zend_generator_resume(zval *object, zend_generator *generator TSRMLS /* Restore executor globals */ EG(return_value_ptr_ptr) = original_return_value_ptr_ptr; + EG(current_execute_data) = original_execute_data; EG(opline_ptr) = original_opline_ptr; EG(active_op_array) = original_active_op_array; EG(active_symbol_table) = original_active_symbol_table; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php