1.2.789. New Object Then Immediate Call¶
This rule reports immediate calls on a new object. This can be simplified with a parenthesis structure, including with the assignation inside the parenthesis.
It is also being discussed to drop the parenthesis altogether.
<?php
$a = new Foo();
$a->bar();
($a = new Foo())->bar();
?>
See also new MyClass()->method() without parentheses.
1.2.789.1. Suggestions¶
Condense the two expressions into one
1.2.789.2. Specs¶
Short name |
Classes/NewThenCall |
Rulesets |
|
Exakat since |
2.6.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |