Back to questions
JuniorTheoryCommon
What does the program print?
<?php
function price($amount, $discount = 0, $tax = 20)
{
return $amount - $discount + $tax;
}
echo price(100, tax: 0), ' ', price(100, 5), "\n";100 115
- Expecting an error for the skipped
$discount: a parameter with a default may be left out, and the named argument after it sets$taxdirectly. - Expecting the
5inprice(100, 5)to reach$tax: positional arguments fill parameters left to right, so5is$discountand the call is100 - 5 + 20.
- What happens if you call
price(tax: 0)without the first argument? - Why does PHP refuse
price(tax: 0, 100)before the program runs?