3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function &foo() { $x = array(1,2,3); $y =& $x; yield $y; yield $x; echo "Gen: "; var_dump($x); echo "Gen: "; var_dump($y); $x[] = 100; echo "Gen: "; var_dump($x); echo "Gen: "; var_dump($y); yield 'done'; } $gen = foo(); $a =& $gen->current(); $gen->next(); $b =& $gen->current(); var_dump($a); var_dump($b); $b[] = 42; var_dump($a); var_dump($b); $gen->next();
based on fGYCF
Output for 7.0.0 - 7.2.0
Notice: Only variables should be assigned by reference in /in/MgdnW on line 17 Notice: Only variables should be assigned by reference in /in/MgdnW on line 19 array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(42) } Gen: array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } Gen: array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } Gen: array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(100) } Gen: array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(100) } Notice: Only variable references should be yielded by reference in /in/MgdnW on line 13
Output for 5.5.24 - 5.6.21
Strict Standards: Only variables should be assigned by reference in /in/MgdnW on line 17 Strict Standards: Only variables should be assigned by reference in /in/MgdnW on line 19 array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(42) } Gen: array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } Gen: array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } Gen: array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(100) } Gen: array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(100) } Notice: Only variable references should be yielded by reference in /in/MgdnW on line 13
Output for 5.4.1 - 5.4.45
Parse error: syntax error, unexpected '$y' (T_VARIABLE) in /in/MgdnW on line 6
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/MgdnW on line 6
Process exited with code 255.