by nikic · 12y ago · 0 comments
* Namespaces, closures and FPM were already in PHP 5.3
* The built-in web server was already in PHP 5.4
* Improved variadic functions, argument unpacking and phpdbg will be in PHP 5.6, which goes to beta in about a week.
Can you give an example? I googled "closure conversion" but didn't understand.
public function getTotal($tax)
{
$total = 0.00;
$callback =
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);
}
In other languages that have true closures, the anonymous function "closes over" the lexical scope in which it was declared.The necessity of `use` is, IMHO, ridiculous.