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

Better readability; less code is better code

Share:
ricardoboss avatar
ricardoboss
voted yes
1

Agree

Share:
clouetjm avatar
clouetjm
voted yes
1

better readability

Share:
mehranhadidi avatar
mehranhadidi
voted yes
1

Less characters without loss of readability is always good.

Share:
alex-wells avatar
alex-wells
voted yes
1

Looks cool. Hope it does not have weird problems and will not affect performance.

Share:
raszekster avatar
raszekster
voted yes
1

Readable and clean

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

Check out another RFCs

Property Hooks

A new way of interacting with properties

66
130 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
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!