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

It is very annoying to wrap new class into parentheses.

Share:
theese avatar
theese
voted yes
1

Yeah finally. its necessary

Share:
rezamasoudi avatar
rezamasoudi
voted yes
1

This syntax, will make the code more readable, clean.

Share:
hamzatopo avatar
hamzatopo
voted yes
1

This is very clean

Share:
williamug avatar
williamug
voted yes
1

I love it, it's cleaner

Share:
cesarmtorres avatar
cesarmtorres
voted yes
1

It is really confusing to read since having the space breaks the way PHP handles spaces in all other places. It is incoherent.

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

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

Check out another RFCs

Asymmetric Visibility v2

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

19
16 yes
40 no
Property Hooks

A new way of interacting with properties

70
141 yes
90 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
264 no
RSS Feed Contribute Watch on YouTube Our License
© 2024 RFC Vote. This project is open source. Contribute and collaborate with us!