1.2.782. 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.782.1. Suggestions

  • Condense the two expressions into one

1.2.782.2. Specs

Short name

Classes/NewThenCall

Rulesets

All, Analyze, Class Review

Exakat since

2.6.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud