Skip to content

[PHP^8.2] Access to an undefined property when type hinting interface with @property #10302

@samlev

Description

@samlev

Bug report

Similar to #8537 there is still an issue when a variable is type-hinted with an interface that has a @property, or @property-read declaration. From PHP8.2 onwards PHPStan is unable to recognise these declarations on interfaces.

/** 
 * @property int $x
 * @property-read int $y
 * @property-write int $z
 */
interface SampleInterface
{
}

function test(SampleInterface $test): void
{
    echo $test->x;
    echo $test->y;
    $test->z = 5;
}

Code snippet that reproduces the problem

https://phpstan.org/r/a199e998-8445-4590-9942-fe4b04a704bd

Expected output

No errors!

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

No response

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