Skip to content

ReadOnlyPropertyAssignRule is not aware of __construct() method on traits #7314

@mpyw

Description

@mpyw

Bug report

PHPStan version: 1.7.1

ReadOnlyPropertyAssignRule is not aware of __construct() method on traits.

class UserId1
{
    public function __construct(
        public readonly int $id, // Valid
    ) {
    }
}

trait HasId
{
    public function __construct(
        public readonly int $id, // Not Valid (Really?)
    ) {
    }
}
class UserId2
{
    use HasId;
}

Code snippet that reproduces the problem

https://phpstan.org/r/508524bf-d8ea-4e2d-86e2-9324ce575b1e

Expected output

No Errors

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