phpstan: [PHP^8.2] Access to an undefined property when type hinting interface with `@property`
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
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Reactions: 1
- Comments: 17 (8 by maintainers)
This is now possible to solve with
@phpstan-require-extendsand@phpstan-require-implements.Here’s an example: https://phpstan.org/r/2dec4d59-482d-4894-ba05-0c2453e28f2b
@mattvb91 If you have any questions please first try it out and then report if it doesn’t work as expected.
In the future this will be possible to solve with
@phpstan-require-extendsabove an interface or a trait.Yes, I’m thinking I’d allow this for interfaces with
@mixinbut I’d need to look into if it really solves all use cases.Only with this 😦