3

I have a list of objects which I retrieve in the following way:

list($var1, $var2, $var3) = $helper->getStuff();

except longer.

Now, all of these variables are of the same class, Foo, and I want to annotate them so that the IDE (PHPStorm) realizes what I'm doing.

Normally, getting one variable at a time, I would go

/**@var Foo $var1 */
$var1 = ...;

/**@var Foo $var2 */
$var2 = ...;

etc. But how can I accomplish this, with the list($var1, $var2, $var3) = ...; way of getting them?

Ideally, it would be something like

/**@var Foo $var1, $var2, $var3 */

so that I could consolidate them into one line. And yes, I've tried that, both comma-separated and space-separated.

6
  • The annotation will work in those cases too Commented Aug 23, 2016 at 12:57
  • Just curious if you have tried 2016.2.1 (EAP build at the moment)? There is a chance that it is better there (as long as $helper->getStuff() has proper @return tag annotation). If not -- then it might get improved in 2016.3 version Commented Aug 23, 2016 at 14:03
  • @LazyOne - Yeah, one can usually do that with a return tag. However, the getStuff() function is annotated with @return Foo[] but it doesn't carry over. Commented Aug 23, 2016 at 15:42
  • @Alec Accordingly to youtrack.jetbrains.com/issue/WI-20192 ticket it will be supported/working better in 2016.3 for cases where original variable/function return is an array of objects of specific type (e.g. Foo[]) Commented Aug 23, 2016 at 16:23
  • @LazyOne - Excellent catch! Looking forward to 2016.3 then! Commented Aug 23, 2016 at 16:37

1 Answer 1

4

You can place them all in a single block above it. For example:

/**
 * @var Foo $var1
 * @var Foo $var2
 * @var Foo $var3
 */
list($var1, $var2, $var3) = $helper->getStuff();

You can wedge them all into one line if you use separate blocks, like:

/**@var Foo $var1*/ /**@var Foo $var2*/ /**@var Foo $var3*/
list($var1, $var2, $var3) = $helper->getStuff();

but I suspect that's not the concise readability you're after.

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

2 Comments

That looks more tidy, but is there no way to annotate them all on one line?
Haha, A for effort though! I'll be using the first variant you proposed. :)

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.