简体   繁体   中英

PhpStorm code auto completion for PHP const nested array

I want some nested JSON like var for some configuration.

In JavaScript, the obj, PhpStorm can show candidate properties:

const ABC = {
  A1: 123,
  A2: [
    B1: 33,
    B2: 44
  ]
}

// after type each dot `.`, PhpStorm can show candidate properties
console.log(ABC.A2.B1)

But not working for PHP, PhpStorm can only show candidate for the first level of the array, not for deeper array, and doesn't show error tips if index not exist:

<?php

class TT
{
    const  ABC = [
        'A1' => 123,
        'A2' => [
            'B1' => 123,
            'B2' => 5566
        ]
    ];

    public function f1()
    {
        // PhpStorm can only show candidate for the first level of the array
        // not for deeper array
        echo self::ABC['A2']['B1'];

        // not show error tips for not exist index
        echo self::ABC['A12345']['B1'];
    }
}

ATM code completion works for 1st level array keys only.

Accordingly to devs such tracking and completion (even for 1st level array keys) is a bit resource-intensive operation.

https://youtrack.jetbrains.com/issue/WI-6845 -- watch this ticket (star/vote/comment) to get notified on any progress.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM