On 11 May 2024 15:43:19 BST, "Gina P. Banyard" <intern...@gpb.moe> wrote:
>print, echo, include(_once) and require(_once) do not mandate their "argument"
>to be passed within parenthethis, so making them functions does not simplify
>the lexer/parser nor removes them as keywords.
It's actually a much stronger difference than that: parentheses are not parsed
as surrounding the argument lists for those keywords at all.
A while ago, I added notes to the manual pages of each showing how this can
lead to misleading code, e.g. one of the examples on https://www.php.net/print
is this:
print(1 + 2) * 3;
// outputs "9"; the parentheses cause 1+2 to be evaluated first, then 3*3
// the print statement sees the whole expression as one argument
echo has further peculiarities, because it takes an unparenthesised list of
arguments, and can't be used in an expression.
While it would probably have been better if those had been parsed like
functions to begin with, changing them now would not just be pointless, it
would be actively dangerous, changing the behaviour of existing code.
Regards,
Rowan Tommins
[IMSoP]