Re: RFC proposal : "new" keyword shorthand
| From: | John Bafford | Date: | Fri, 07 Jun 2024 16:30:39 +0000 |
| Subject: | Re: RFC proposal : "new" keyword shorthand | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123540@lists.php.net to get a copy of this message | ||
Hi Benoît,
> On Jun 7, 2024, at 12:03, Benoît Condaminet <condaminet.benoit@gmail.com> wrote:
>
> As a first try, I start updated code to completely make the new keyword optional, like in Dart
> language for example, but it require very big change, with lot of impact (collision with function).
>
> So here is my proposal :
>
> Add a "new" shorthand, using the tilde character : "~"
> I made a POC, and it works well, declaring a new language token T_SHORT_NEW that simply reuse
> ZEND_AST_NEW under the hood.
I would point out that ~ is an existing operator, bitwise not. Is there not the same ambiguity with
that as with not having the new keyword at all? Because PHP has classes and functions in different
namespaces ~SomeClass() looks exactly the same as ~SomeFunction(), and ~$someVar() would be just as
ambiguous.
I would prefer to see the new keyword go away as well, but as long as functions and classes are in
separate namespaces, that might be difficult.
-John