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

由于列表是一个非常常见的词,因此无法搜索该主题。

list($total, $tax) = $this->getOrderAmounts();

这被认为是不好的做法或代码味道? 我觉得我最近一直在使用它作为一个糟糕的捷径。

另外: list实际上是一个语言结构,而不是一个函数


我个人不会使用列表,因为它是如此“不精确”。 考虑这个: -

$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

但是,如果你犯了一个错误: -

$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

这会很容易: -

$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/92675.html

上一篇: Is using PHP's `list` function considered bad practice?

下一篇: Why is PHP's explode wrong?