A method named like its class is no longer run as the constructor
What it finds
A method named like its class, in a class without __construct: PHP 4 ran such a method as the constructor, and PHP 8 no longer does, so code written that way leaves new objects uninitialized. Classes in a namespace never had such constructors and are left alone.
From the rule's source, class_named_method.rs.
<?phpclass Widget{ private $size; public function Widget($size)tx0 reports: Widget is named like its class but is not a constructor { $this->size = $size; }} class Gadget{ public function __construct() { } public function gadget() { }} 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:class-named-method" = "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:class-named-method] reason="..."tx0 explain tx0/php:class-named-method shows the same in the terminal. Found a false positive? Report it.