Skip to content

Support PHP 8.4 property hooks #731

Closed
@jnoordsij

Description

@jnoordsij

Is your feature request related to a problem?

Describe the solution you'd like

PHP 8.4 has been recently released, introducing property hooks which allows for easier customization to get and set logic of properties.

This new syntax yields some errors when linted with current setup. A small example I've created:

<?php

namespace Foo;

class Foo
{
    private string $privateBar = 'bar';

    public string $bar {
        get => $this->privateBar;
        set(string $bar) {
            $this->privateBar = $bar;
        }
    }
}

When running phpcs --standard=PSR12 foo.php this yields

FILE: ...foo.php
------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 4 LINES
------------------------------------------------------------------------------
  9 | ERROR | There must not be more than one property declared per statement
 10 | ERROR | Visibility must be declared on property "$this"
 11 | ERROR | There must not be more than one property declared per statement
 11 | ERROR | Visibility must be declared on property "$bar"
 12 | ERROR | There must not be more than one property declared per statement
 12 | ERROR | Visibility must be declared on property "$this"
------------------------------------------------------------------------------

I'd expect no errors linting this.

Additional context (optional)

There might be additional new PHP 8.4 syntax that require additional changes. Maybe this should be listed on #106 or a new tracking issue for PHP 8.4 syntax? I could not find an existing source for tracking 8.4 compatibility.

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