WordPress/WordPress-Coding-Standards

Review sniff handling of PHP 7.4 typed properties

dingo-d opened this issue · 1 comments

PHP 7.4 added support for typed class properties.

class User {
  private $id;
  private $name;

  public function __construct(int $id, string $name) {
    $this->id = $id;
    $this->name = $name;
  }

  // getters and setters set here
}

Which can be shortened to:

class User {
    public int $id;
    public string $name;
 
    public function __construct(int $id, string $name) {
        $this->id = $id;
        $this->name = $name;
    }
}

We already include Generic.PHP.LowerCaseType sniff, and once we up the PHPCS version to >= 3.6.0, we should have the support for checking the typed properties in the class.

Refs:

Related to #764