我正在检查一些PHP 5.3.0
功能并在网站上运行一些看起来相当有趣的代码:
public function getTotal($tax)
{
$total = 0.00;
$callback =
/* This line here: */
function ($quantity, $product) use ($tax, &$total)
{
$pricePerItem = constant(__CLASS__ . "::PRICE_" .
strtoupper($product));
$total += ($pricePerItem * $quantity) * ($tax + 1.0);
};
array_walk($this->products, $callback);
return round($total, 2);
}
作为 匿名函数 上的例子之一。
有人知道吗?有任何文档吗?它看起来很邪恶,是否应该使用它?