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!
78%
22%
1

I honestly don't really care about that small sugar, but I lean more towards yes than no, so ship it

Share:
Contributor serhii avatar
serhii
voted yes
1

Parentheses do not add anything to a human to understand what is going on.

Since PHP does not require curly braces in strings most of the time, we can get rid of those parentheses too (when they are not required by the language anymore).

Share:
eugen avatar
eugen
voted yes
1

The absence of parentheses leads to a decrease in clarity of intent

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

It just makes sense and also optional, so whoever doesn't like it can go back to using parentheses.

Share:
medabkari avatar
medabkari
voted yes
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

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
Interface Default Methods

Interface Default Methods improves backwards compatibility when changing interfaces, but also add a way to have multi-inheritance in PHP.

95
168 yes
263 no
Property Hooks

A new way of interacting with properties

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