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

上一篇: 这是否被认为是“网页抓取”? 它是“合法的”吗?

下一篇: 使用PHP的`list`函数被认为是不好的做法?