0

I have this basic code:

    $test = array(
    'nested' => array('test' => 'nada');
);

    function doit()
    {
        global $test;
        $test['nested'][''];
    }

PHPStorm correctly suggests me 'nested' when I press Ctrl+Space
However, I found no way to make it suggest 'test' as member of the 'nested' array.
PHPStorm does not seem to be aware that nested is an array and also has members.

Is that a bug, did I do something wrong ?

According to comment I tried another solution to get completion support:
With no luck either

    class test
    {
      public static $nested = array('test' => 'nada');
}

    function doit()
    {
        $completeme = test::$nested;
        $completeme['']; // no completion working

        /** @var test::nested $completeme */
        $completeme = test::$nested;
        $completeme['']; // no completion working
    }

Same issue for me at the IDE, this time it is an array inside a class.
test::nested[''] << this works, I get completion. But as soon as I make a copy of it I found no way to get completion again or to specify the type using phpdoc.

John
  • 7,507
  • 3
  • 52
  • 52
  • 1
    This feature is not implemented. Even remembering keys for first level array add some noticeable overhead (memory + CPU). Considering this + the fact that in majority of cases first level is enough, the implementation for other levels was simply put on hold. – LazyOne Sep 30 '14 at 08:56
  • They should have added a PHPdoc parameter to force resursive completion :/ I tried another way, I tried using a class instead and the problem remains. Now it is a first level array but I can not get completion when making a copy of it. – John Sep 30 '14 at 15:44
  • I could be wrong here (since I do not have access to the actual code) but as far as I'm aware it links array keys to the actual array/variable name .. so such assignment (one variable to another) will not work (at least I have never seen it working for me). This feature has pretty limited usage case and mainly targeted on completion some global arrays ($_SERVER etc) or arrays within a class/function (e.g. `$cfg` property of your class that holds class configuration details (instead of keeping them in separate fields)). – LazyOne Sep 30 '14 at 15:57

1 Answers1

0

This feature is not implemented (original array keys support ticket).

AFAIK even remembering keys for first level array adds some noticeable overhead (memory + CPU -- depends on actual project and how heavily arrays/variables are used). Considering this + the fact that in majority of cases first level is enough, the implementation for other levels was simply put on hold.

https://youtrack.jetbrains.com/issue/WI-6845 -- star/vote/comment to get notified on progress.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
  • But I suppose that does not count for my second example ? Usually I can solve it with a PHPdoc comment @var but in this case not. – John Sep 30 '14 at 19:40
  • AFAIK it is working in a scope .. and I do not see any that that it would work with such PHPDoc comment. Any suggestions -- feel free to comment existing tickets or submit new one at their Issue Tracker at http://youtrack.jetbrains.com/issues/WI . As it stands right now .. 1) there were no much progress in working with array keys in recent version and 2) aforementioned tickets are not set yet to be implemented for any specific future version (just generic "x.x" -- one of the future versions) – LazyOne Sep 30 '14 at 20:32