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!
83%
17%
1

The code will be easier to read

Share:
stevad avatar
stevad
voted yes
1

If we remove parentheses for this case, why having them for the if statement and so on?

I think it's necessary for the parentheses to be kept because you have to prioritize the object instanciation to use a method it exposes.

Share:
rinodrummer avatar
rinodrummer
voted no
1

It could led to typos because of the space between New and the Class instantiated, the "old" approach is more readable too

Share:
cristianovalenca avatar
cristianovalenca
voted no
1

first of all it looks wrong

Share:
siada-apius avatar
siada-apius
voted no
1

its a method on an object, which itself could be chainable; wrapping it in brackets makes it it object

Share:
fredbradley avatar
fredbradley
voted no
1

not logical to remove them.

Share:
dsentker avatar
dsentker
voted no
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

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
The Pipe Operator

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

92
268 yes
130 no
Property Hooks

A new way of interacting with properties

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