Re: [RFC] Transform exit() from a language construct into a standard function
| From: | Rowan Tommins [IMSoP] | Date: | Sat, 11 May 2024 16:14:12 +0000 |
| Subject: | Re: [RFC] Transform exit() from a language construct into a standard function | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123312@lists.php.net to get a copy of this message | ||
On 11 May 2024 15:43:19 BST, "Gina P. Banyard" <internals@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]