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

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
1

This is one of the things that I come across so often, numerous times within every project. It makes sense for PHP to get rid of boilerplate wherever it can. If the compiler can figure out the details, then I prefer not having to micro-manage every bracket.

Share:
Contributor brent avatar
brent
voted yes

Check out another RFCs

The Pipe Operator

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

90
262 yes
122 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!