1--TEST-- 2Exceptions in linear yield from setup 3--FILE-- 4<?php 5function from($off) { 6 debug_print_backtrace(); 7 yield $off + 1; 8} 9 10function gen() { 11 yield 1; 12 debug_print_backtrace(); 13 yield 2; 14 yield from from(2); 15 debug_print_backtrace(); 16} 17 18print "\nImplicit foreach:\n"; 19foreach (gen() as $v) { 20 var_dump($v); 21} 22 23print "\nExplicit iterator:\n"; 24for ($gen = gen(); $gen->valid(); $gen->next()) { 25 var_dump($gen->current()); 26} 27?> 28--EXPECTF-- 29Implicit foreach: 30int(1) 31#0 gen() called at [%s:%d] 32int(2) 33#0 from(2) called at [%s:%d] 34#1 gen() called at [%s:%d] 35int(3) 36#0 gen() called at [%s:%d] 37 38Explicit iterator: 39int(1) 40#0 gen() 41#1 Generator->next() called at [%s:%d] 42int(2) 43#0 from(2) called at [%s:%d] 44#1 gen() 45#2 Generator->next() called at [%s:%d] 46int(3) 47#0 gen() 48#1 Generator->next() called at [%s:%d] 49