mirror of
https://github.com/php/php-src.git
synced 2024-09-28 21:36:12 +00:00
c9709bfbd7
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).
24 lines
279 B
PHP
24 lines
279 B
PHP
--TEST--
|
|
Simple generator xrange() test
|
|
--FILE--
|
|
<?php
|
|
|
|
function xrange($start, $end, $step = 1) {
|
|
for ($i = $start; $i <= $end; $i += $step) {
|
|
yield $i;
|
|
}
|
|
}
|
|
|
|
foreach (xrange(10, 20, 2) as $i) {
|
|
var_dump($i);
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
int(10)
|
|
int(12)
|
|
int(14)
|
|
int(16)
|
|
int(18)
|
|
int(20)
|