mirror of
https://github.com/php/php-src.git
synced 2026-03-26 09:12:14 +01:00
Generators are now automatically detected by the presence of a `yield` expression in their body. This removes the ZEND_SUSPEND_AND_RETURN_GENERATOR opcode. Instead additional checks for ZEND_ACC_GENERATOR are added to the fcall_common helper and zend_call_function. This also adds a new function zend_generator_create_zval, which handles the actual creation of the generator zval from an op array. I feel like I should deglobalize the zend_create_execute_data_from_op_array code a bit. It currently changes EG(current_execute_data) and EG(opline_ptr) which is somewhat confusing (given the name).
33 lines
393 B
PHP
33 lines
393 B
PHP
--TEST--
|
|
Generators can be cloned
|
|
--FILE--
|
|
<?php
|
|
|
|
function firstN($end) {
|
|
for ($i = 0; $i < $end; ++$i) {
|
|
yield $i;
|
|
}
|
|
}
|
|
|
|
$g1 = firstN(5);
|
|
var_dump($g1->current());
|
|
$g1->next();
|
|
|
|
$g2 = clone $g1;
|
|
var_dump($g2->current());
|
|
$g2->next();
|
|
|
|
var_dump($g2->current());
|
|
var_dump($g1->current());
|
|
|
|
$g1->next();
|
|
var_dump($g1->current());
|
|
|
|
?>
|
|
--EXPECT--
|
|
int(0)
|
|
int(1)
|
|
int(2)
|
|
int(1)
|
|
int(2)
|