Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Initialize read-only properties in child classes #12871

@blue32a

Description

@blue32a

Bug report

Read-only properties can be initialized in child classes.

The following code works:
https://3v4l.org/PDmd0#v8.4.6

As of PHP 8.4.0, readonly properties are implicitly protected(set), so may be set from child classes. That may be overridden explicitly if desired.
-- https://www.php.net/manual/en/language.oop5.properties.php#language.oop5.properties.readonly-properties

But PHPStan reports property.readOnlyAssignOutOfClass.

Code snippet that reproduces the problem

https://phpstan.org/r/8e4203cd-9044-4f40-b350-d9ad8b40c4de

Expected output

No errors are reported

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

Yes!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions