new MyClass()->method() without parentheses

This RFC allows to omit parentheses around the new expression when constructor arguments' parentheses are present.

$highlighter = (new Highlighter())->withGutter();
$highlighter = new Highlighter()->withGutter();

It also works with accessing properties, constants, etc.

new MyClass()::CONSTANT;
new MyClass()::$staticProperty;
new MyClass()::staticMethod();
new MyClass()->property;
new MyClass()->method();
new MyClass()();
Click the bar to cast your vote!
85%
15%
1

lgtm

Share:
thomas-kl1 avatar
thomas-kl1
voted yes
1

I think this feels a lot cleaner. Not sure what the internal implications of this are but I like it.

Share:
adamtomat avatar
adamtomat
voted yes
1

Much cleaner

Share:
christophercarranza avatar
christophercarranz...
voted yes
1

Makes it just cleaner

Share:
eydamos avatar
eydamos
voted yes
1

Ship it!

Share:
tomschlick avatar
tomschlick
voted yes
1

me parece una buena adición al lenguaje

Share:
cristyanvalera avatar
cristyanvalera
voted yes
1

It is a good quality of live improvement, I can't think of a possible downside

Share:
nabeel avatar
nabeel
voted yes
1

I think I would be fine if this had been in PHP all along, but for all existing developers this proposal really messes up my feeling for reading code. PHP always considers a space between words/symbols as a separator between two things. If you want to combine the result of that, you need to always use parentheses, so why create an exception here?

Share:
ralphjsmit avatar
ralphjsmit
voted no
1

Less code is better code, this is implicit language priority no need to express it

Share:
remy-theroux avatar
remy-theroux
voted yes

Check out another RFCs

The Pipe Operator

The "pipe operator" |> allows you to chain multiple function calls in a more convenient way.

93
272 yes
131 no
Asymmetric Visibility v2

A new syntax for declaring the “set” operation visibility of an object property

18
16 yes
39 no
Short Closures 2.0

This RFC proposes a way to have multi-line short closures — closures that don't need explicit use statements, but can still have multiple lines and a return statement.

101
373 yes
66 no
RSS Feed Contribute Watch on YouTube Our License
© 2024 RFC Vote. This project is open source. Contribute and collaborate with us!