3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php define('MAX_LOOPS',5); function withRefValue($elements, $transform) { for ($i=0; $i<$elements; $i++) { $a[] = "v.$i"; } $counter=0; foreach ($a as $k=>&$v) { eval($transform); $counter++; if ($counter>MAX_LOOPS) { break; } } echo "--> State of array after loop:\n"; var_dump($a); } echo "\nPopping elements off end of an unreferenced array, using &\$value."; $transform = 'array_pop($a);'; withRefValue(1, $transform); withRefValue(2, $transform); withRefValue(3, $transform); withRefValue(4, $transform); withRefValue(5, $transform); withRefValue(6, $transform); withRefValue(7, $transform); withRefValue(8, $transform); withRefValue(9, $transform); withRefValue(10, $transform); withRefValue(11, $transform); withRefValue(12, $transform);
based on VZnrV
Output for 7.0.0 - 7.1.0
Popping elements off end of an unreferenced array, using &$value.--> State of array after loop: array(0) { } --> State of array after loop: array(1) { [0]=> &string(3) "v.0" } --> State of array after loop: array(1) { [0]=> string(3) "v.0" } --> State of array after loop: array(2) { [0]=> string(3) "v.0" [1]=> &string(3) "v.1" } --> State of array after loop: array(2) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" } --> State of array after loop: array(3) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> &string(3) "v.2" } --> State of array after loop: array(3) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" } --> State of array after loop: array(4) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> &string(3) "v.3" } --> State of array after loop: array(4) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" } --> State of array after loop: array(5) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" [4]=> &string(3) "v.4" } --> State of array after loop: array(5) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" [4]=> string(3) "v.4" } --> State of array after loop: array(6) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" [4]=> string(3) "v.4" [5]=> &string(3) "v.5" }
Output for 5.2.2 - 5.6.28
Popping elements off end of an unreferenced array, using &$value.--> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(1) { [0]=> string(3) "v.0" } --> State of array after loop: array(0) { } --> State of array after loop: array(2) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" } --> State of array after loop: array(1) { [0]=> string(3) "v.0" } --> State of array after loop: array(3) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" } --> State of array after loop: array(2) { [0]=> string(3) "v.0" [1]=> &string(3) "v.1" } --> State of array after loop: array(4) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" } --> State of array after loop: array(4) { [0]=> &string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" } --> State of array after loop: array(5) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" [4]=> string(3) "v.4" } --> State of array after loop: array(6) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" [4]=> string(3) "v.4" [5]=> &string(3) "v.5" }
Output for 5.0.0 - 5.2.1
Popping elements off end of an unreferenced array, using &$value.--> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(1) { [0]=> string(3) "v.0" } --> State of array after loop: array(2) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" } --> State of array after loop: array(3) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" } --> State of array after loop: array(4) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" } --> State of array after loop: array(5) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" [4]=> string(3) "v.4" } --> State of array after loop: array(6) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" [4]=> string(3) "v.4" [5]=> string(3) "v.5" }
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /in/qRjoV on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /in/qRjoV on line 12
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /in/qRjoV on line 12
Process exited with code 255.