A constructor returns a value, which new drops
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.
<?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; }} 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:
[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.