<?php function foo($x) { $x = $x + 10; } $y = 5; foo($y); echo $y, "\n"; $y = 5; //ERROR: bad, passing reference where was expecting regular parameter foo(&$y); echo $y, "\n"; function taking_a_ref(&$x) { $x = $x + 10; } $y = 5; taking_a_ref(&$y); //SKIP: not indicating a "pass-by-ref" at call site is bad, but skip cos too many taking_a_ref($y); //ERROR: keyword argument to reference parameter is bad taking_a_ref($x = 2);
<?php function foo($x) { $x = $x + 10; } $y = 5; foo($y); echo $y, "\n"; $y = 5; //ERROR: bad, passing reference where was expecting regular parameter foo(&$y); echo $y, "\n"; function taking_a_ref(&$x) { $x = $x + 10; } $y = 5; taking_a_ref(&$y); //SKIP: not indicating a "pass-by-ref" at call site is bad, but skip cos too many taking_a_ref($y);
<?php function taking_a_ref(&$x) { $x = $x + 10; } $x = 0; taking_a_ref($x = 2); // output = 2 ... insane echo $x; $x = 0; taking_a_ref($x); echo $x; function taking_an_array_ref(&$x) { $x[] = 'foo'; } taking_an_array_ref($array = array()); // output is empty array, ... insane var_dump($array); $array = array(); taking_an_array_ref($array); var_dump($array);