1

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);
2
  • 1
    1) (a bit off topic) You are not using PHPDoc -- it's an ordinary comment that IDE interprets the same as PHPDoc. PHPDoc comments start with /** (2 asterisk symbols) 2) Let me clarify this first -- so $categories is an array of Category instances -- right? If so -- /** @var Category[] $categories */ 3) (general note, since I do not know how the rest of the code looks -- it may be all fine from your end) Try providing correct @return tag for functions as well as typehinting fields via @var -- this way local vars have bigger changes of being auto-deducted correctly. Commented Jan 28, 2017 at 20:16
  • @LazyOne, thanks! works fine now! Commented Jan 28, 2017 at 21:43

1 Answer 1

1

The answer appeared to be:

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

Thank you LazyOne!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.