Stan Fad
Stan Fad

Reputation: 1234

PhpStorm - Method not found for object which is array element

I know that for variables which aren't declared as types PhpStorm doesn't know where to look for method calls on variable names sometimes.

I know how to solve it for simple variable by providing typehint via simple PHPDoc comment :

/* @var Category $category */
$category->getNameTranslit();

but how can I do this for methods called for array element?

$categories[$key]->setIsActive(true);

Upvotes: 1

Views: 438

Answers (1)

Stan Fad
Stan Fad

Reputation: 1234

The answer appeared to be:

 /** @var Category[] $categories */
 $categories[$key]->setIsActive(true);

Thank you LazyOne!

Upvotes: 1

Related Questions