Skip to content

ConstructorNameSniff false negative on PHP 8+ #3822

Open
@gsteel

Description

@gsteel

PHP4 style constructors are no longer possible on PHP 8+

This sniff therefore yields false negative for a class such as:

class Something {
   public function something(): void
   {
   }
}

if ($methodName === $className) {
if (in_array('__construct', $this->functionList, true) === false) {
$error = 'PHP4 style constructors are not allowed; use "__construct()" instead';
$phpcsFile->addError($error, $stackPtr, 'OldStyle');
}
} else if ($methodName !== '__construct') {
// Not a constructor.
return;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions