3v4l.org

run code in 300+ PHP versions simultaneously
<?php function &foo() { $x = array(1,2,3); yield $x; echo "Gen: "; var_dump($x); $x[] = 99; return $x; } $rets = array(); $gen = foo(); foreach ($gen as &$val) { var_dump($val); $val[] = 42; $rets[] =& $val; } $rv =& $gen->getReturn(); var_dump($rv); $rets[0][] = 100; var_dump($rv); $rv[] = 200; var_dump($rv); var_dump($gen->getReturn()); var_dump($rets);
Output for git.master, git.master_jit, rfc.property-hooks
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(42) } Notice: Only variables should be assigned by reference in /in/h2fdo on line 18 array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(42) [4]=> int(99) } array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(42) [4]=> int(99) } array(6) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(42) [4]=> int(99) [5]=> int(200) } array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(42) [4]=> int(99) } array(1) { [0]=> &array(6) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(42) [4]=> int(99) [5]=> int(100) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
59.55 ms | 403 KiB | 8 Q