Using generics for constructor property

Hi,

In PhpStorm 2021.2.3 i can use generics for method return type:

/** @return array<MyModel> */

function myMethod(): array { ... }

Also for class property:

/** @var array<MyModel> */

public array $myProp;

But if i use php 8 constructor property it doesn't work anymore!

class MyClass {

  function __constructor(

    /** @var array<MyModel> */

    public array $myProp

  ) {}

}

$obj = new MyClass([new MyModel(...)]);

$obj->myProp[0]-> // no suggestion for MyModel props! :(

Please add this feature to next PhpStorm version!

Thanks.

2 comments
Comment actions Permalink

Hello,

As a side gentle notice, the official PhpStorm YouTrack section is the best place to submit bugs & feature requests, just in case:
https://youtrack.jetbrains.com/newIssue

What is about your request, I am not sure if I totally follow it, could you please share a full example or a test project?

0
Comment actions Permalink

@Vasiliy Yur

What is about your request, I am not sure if I totally follow it,

OP typehints constructor's parameter (promoted property) using plain @var tag... which is simply wrong.

@ArashT

Use PHPDoc for constructor and correct @param tag for that (it's a parameter after all)

0

Please sign in to leave a comment.