Is using PHP's `list` function considered bad practice?
Could not search for this topic due to list being a very common word.
list($total, $tax) = $this->getOrderAmounts();
Is this considered bad practice or code smell? I feel like I've been using it as a bad shortcut recently.
Aside: list
is actually a language construct, not a function
I personally wouldn't use list because it is so "not precise". Consider this :-
$rainbow = array('violet', 'indigo','blue','green','yellow','orange','red');
list($violet,,,,,,$red) = $rainbow;
echo "$violet has low wavelength and $red has highest wavelength"; //Outputs violet has low wavelength and red has highest wavelength
But if you make a mistake :-
$rainbow = array('violet', 'indigo','blue','green','yellow','orange','red');
list($violet,,,,,$red) = $rainbow;
echo "$violet has low wavelength and $red has highest wavelength"; //violet has low wavelength and orange has highest wavelength
This would be so easier :-
$rainbow = array('violet', 'indigo','blue','green','yellow','orange','red');
echo "$rainbow[0] has low wavelength and $rainbow[6] has highest wavelength";
链接地址: http://www.djcxy.com/p/92676.html