php - Is it necessary to pass by reference explicitly? -
for example shuffle(&$array);
is bad practice leave out &
sign when passing argument functions one? because it's working without too...
in php 5.3 bad, in earlier versions suppose on sort of meta way can next person read code, not best idea because doesn't do , people confused inclusion (why person doing that? don't it...). &
used 4 times:
- assigning variable reference:
$a =& $b
(a references b) - parameters:
function inc(&$b){$b++;}
(b increment outside of func) - returns:
function &get_thing(){ static $thing; return $thing; }
(you can modify static value) - iterations:
foreach($var $key=>&$val){$val++;}
Comments
Post a Comment