8

In PHPStorm, the Code Hinting for an object array is simple and awesome;

class FooList {
    public function __construct(){
        $this->_fooList[] = new Foo(1);
        $this->_fooList[] = new Foo(2);
        $this->_fooList[] = new Foo(3);
        $this->_fooList[] = new Foo(4);
    }

    /**
     * @return Foo[]
     */
    getFoos() {
        return $this->_fooList;
    }
}

So if I do...

$fooList = new FooList();

foreach($fooList as $foo)
{
    // Nice hinting.
    $foo->FooMethod...
}

PHPStorm understands that $fooList is an array of Foos, and therefore knows that $foo's type is Foo.

The problem is that I want an array of FooList.

$listOfLists[] = new FooList();
$listOfLists[] = new FooList();
$listOfLists[] = new FooList();
$listOfLists[] = new FooList();

foreach ($listOfLists as $fooList)
{
    foreach($fooList as $foo)
    {
        // No code hinting for $foo :(
    }
}

I know that you can code hint manually inside the foreach, like...

foreach ($listOfLists as $fooList)
{
    foreach($fooList as $foo)
    {
        /** $var $foo Foo */
        // Code hinting, yay!!
    }
}

Or ...

foreach ($listOfLists as $fooList)
{
    /** $var $fooList Foo[] */
    foreach($fooList as $foo)
    {
        // Code hinting, yay!!
    }
}

But I think that is ugly, as $listOfLists is build of Foo arrays, it should know what I am talking about without reminding it every time I implement a listOfLists.

Is there a way to implement this?

Hector Ordonez
  • 1,044
  • 1
  • 12
  • 20
  • 3
    http://youtrack.jetbrains.com/issue/WI-12303 – LazyOne Dec 17 '13 at 23:01
  • Thanks LazyOne! I already Upvoted that issue. If you reply this post with an answer explaining that this issue is actually a requested feature, I'll accept it. – Hector Ordonez Dec 18 '13 at 21:00
  • 3
    This question appears to be off-topic because it is about a feature request in a 3rd party application. – kittycat Dec 20 '13 at 04:57
  • 1
    @crypticツ Yeah, but it's also a development tool and therefore on-topic :) – Ja͢ck Dec 20 '13 at 05:12
  • @crypticツ With the amount of questions related to IDEs (Eclipse, Netbeabs, PHPStorm, etc...), your accusing lots of questions to be off-topic ;) – Hector Ordonez Dec 21 '13 at 12:28
  • 2
    @MrMe: The only reason I said this is off-topic is that is is about a "feature request". The first comment has clearly shown that the feature does not exist and has been requested, and your comment has shown you are asking it to be posted as an answer. If we posted every feature request for every IDE that would be crazy right? This question should be removed as you got your answer in the comment. It's basically like making a post about a bug in some software, which is definitely off-topic. – kittycat Dec 21 '13 at 13:38
  • @crypticツ That does have sense. I agree with you. Thanks for the clarification! – Hector Ordonez Dec 21 '13 at 19:29
  • This answer/question helped me - so i´m against removal – Benjamin Sep 16 '14 at 12:40

1 Answers1

10

Per the bug report linked in the comments by @LazyOne, as of PhpStorm EAP 138.256 (thus in PHPStorm 8) uniform multi-level array doc parsing is now supported.

This means you can now do this:

/**
 * @var $listOfLists Foo[][]
 */
$listOfLists[] = (new FooList())->getFoos();
$listOfLists[] = (new FooList())->getFoos();
$listOfLists[] = (new FooList())->getFoos();
$listOfLists[] = (new FooList())->getFoos();

foreach ($listOfLists as $fooList)
{
    foreach($fooList as $foo)
    {
        // Code hinting, yay!!
        $foo->fooMethod();
    }
}

and get the expected:

Screenshot

Community
  • 1
  • 1
user3942918
  • 25,539
  • 11
  • 55
  • 67