Back to questions
JuniorTheoryCommon
What does the program print?
<?php
function double($x)
{
return $x * 2;
}
echo double(double(5)) + 1, "\n";21
- Expecting
11, as if only the inner call ran: its result10becomes the argument of the outer call, sodoubleruns twice and returns20before+ 1. - Expecting
22:+ 1stands outside the parentheses, so it is added to what the outer call returns, not to the outer call's argument.
- What would
double(double(5) + 1)return, and in what order would it be computed? - Why may the call to
doublestand above thefunction doubleline in the file?