A constructor returns a value, which new drops

tx0/php:constructor-return-valuerecommendedwarningreliability/object-contractsdepth fastbug

What it finds

return $this->db; in __construct: new always yields the object, and a value returned by the constructor is dropped. The code usually meant to store the value in a property.

From the rule's source, constructor_return_value.rs.

Example from the rule's tests
<?phpclass Service{    private $db;     public function __construct($db)    {        if (!$db) {            return false;tx0 reports: the constructor returns a value        }        $this->db = $db;        return;    }     public function get()    {        return $this->db;    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/php:constructor-return-value" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/php:constructor-return-value] reason="..."

tx0 explain tx0/php:constructor-return-value shows the same in the terminal. Found a false positive? Report it.