Skip to content

[PHP8.4] Readonly property overrides readwrite property (which is readonly) #12586

@gitomato

Description

@gitomato

Bug report

When a readonly class implements an interface with get only property hooks, PHPStan reports an error.

<?php declare(strict_types = 1);

interface Foo
{
    public string $bar { get; }
}

readonly class FooImpl implements Foo
{
    public function __construct(
        public string $bar,
    ) {}
}

echo new FooImpl('hello')->bar;
Readonly property FooImpl::$bar overrides readwrite property Foo::$bar.

3v4L result:
https://3v4l.org/cFlTM#v8.4.4

Code snippet that reproduces the problem

https://phpstan.org/r/2129fbfb-8734-4ec5-8bc6-2b56e44fa2a6

Expected output

No error.

Did PHPStan help you today? Did it make you happy in any way?

PHPStan is a reliable companion for any solid PHP codebase and I plan to recommend it for every future PHP project.

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