On Tue, Apr 23, 2024 at 1:20 PM Robert Landers <landers.rob...@gmail.com>
wrote:

> On Tue, Apr 23, 2024 at 11:10 AM Valentin Udaltsov
> <udaltsov.valen...@gmail.com> wrote:
> >
> > вт, 9 апр. 2024 г. в 19:41, Larry Garfield <la...@garfieldtech.com>:
> >>
> >> On Mon, Apr 8, 2024, at 6:08 AM, Valentin Udaltsov wrote:
> >> > Hello internals,
> >> >
> >> >
> >> >
> >> > I would like to propose a syntax change for PHP 8.4 that allows to
> >> > immediately access instantiated objects without wrapping the
> expression
> >> > into parentheses.
> >> >
> >> >
> >> >
> >> > This was requested and discussed several times, see:
> >> >
> >> > - https://externals.io/message/66197
> >> >
> >> > - https://bugs.php.net/bug.php?id=70549
> >> >
> >> > - https://externals.io/message/101811
> >> >
> >> > - https://externals.io/message/113953
> >> >
> >> >
> >> >
> >> > Here's what you will be able to write after this change:
> >> >
> >> > ```php
> >> >
> >> > class MyClass
> >> >
> >> > {
> >> >
> >> >     const CONSTANT = 'constant';
> >> >
> >> >     public static $staticProperty = 'staticProperty';
> >> >
> >> >     public static function staticMethod(): string { return
> 'staticMethod'; }
> >> >
> >> >     public $property = 'property';
> >> >
> >> >     public function method(): string { return 'method'; }
> >> >
> >> >     public function __invoke(): string { return '__invoke'; }
> >> >
> >> > }
> >> >
> >> >
> >> >
> >> > var_dump(
> >> >
> >> >     new MyClass()::CONSTANT,        // string(8)  "constant"
> >> >
> >> >     new MyClass()::$staticProperty, // string(14) "staticProperty"
> >> >
> >> >     new MyClass()::staticMethod(),  // string(12) "staticMethod"
> >> >
> >> >     new MyClass()->property,        // string(8)  "property"
> >> >
> >> >     new MyClass()->method(),        // string(6)  "method"
> >> >
> >> >     new MyClass()(),                // string(8)  "__invoke"
> >> >
> >> > );
> >> >
> >> > ```
> >> >
> >> >
> >> >
> >> > For more details see the RFC:
> https://wiki.php.net/rfc/new_without_parentheses
> >> >
> >> > Implementation: https://github.com/php/php-src/pull/13029
> >>
> >> I always thought there was some technical parser reason why this wasn't
> possible.  Maybe that was true in 5.x but isn't anymore?
> >>
> >> I cannot speak to the implementation, but I'm all for the change itself.
> >>
> >> --Larry Garfield
> >
> >
> > Does anyone have additional feedback? I'd like to start voting on
> Thursday, April 25th.
> > I've also added a section on other syntax ideas that have been expressed
> on Twitter and in the PR:
> https://wiki.php.net/rfc/new_without_parentheses#other_syntax_ideas
> > --
> > Valentin
>
> I suspect this will break (badly written) reflection in interesting ways:
>
> https://3v4l.org/mcSNH
>
> This basically breaks dereferencing order of operations and makes it
> inconsistent.
>
> Robert Landers
> Software Engineer
> Utrecht NL
>

I think these scenarios are all covered in the RFC under "This RFC still
does not allow to omit parentheses around the new expression without
constructor arguments' parentheses, because in some cases this leads to an
ambiguity"

Reply via email to