Skip to content

Adding final to a property is not reported #1021

Open

Description

@NopeCharon

Since PHP 8.4, properties can be declared final, either explicitly or implicitly through private(set). Making an existing property final breaks every child class that redeclares it:

// before
class Foo
{
    public int $count = 0;
}

// after
class Foo
{
    final public int $count = 0;
}

// downstream
class Bar extends Foo
{
    public int $count = 1; // Fatal error: Cannot override final property Foo::$count
}

The tool currently reports nothing for this change. Methods have MethodBecameFinal and constants have ClassConstantBecameFinal, but there is no equivalent check for properties.

ReflectionProperty#isFinal() from BetterReflection already accounts for the implicit final of private(set) properties. The check would only need to run for public and protected properties of non-final classes and for trait properties, since properties of a final class can't be redeclared anyway.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions