1--TEST-- 2Generators can yield by-reference 3--FILE-- 4<?php 5 6function &iter(array &$array) { 7 foreach ($array as $key => &$value) { 8 yield $key => $value; 9 } 10} 11 12$array = [1, 2, 3]; 13$iter = iter($array); 14foreach ($iter as &$value) { 15 $value *= -1; 16} 17var_dump($array); 18 19$array = [1, 2, 3]; 20foreach (iter($array) as &$value) { 21 $value *= -1; 22} 23var_dump($array); 24 25?> 26--EXPECT-- 27array(3) { 28 [0]=> 29 int(-1) 30 [1]=> 31 int(-2) 32 [2]=> 33 &int(-3) 34} 35array(3) { 36 [0]=> 37 int(-1) 38 [1]=> 39 int(-2) 40 [2]=> 41 &int(-3) 42} 43