I have a red underline on a defined variable, that is static:

And here is a tooltip:

Is this a bug, or is something wrong with the code?

    Ok, here is the full file to reproduce the error:

    <?php
    
    class Myclass {
    
      public static function test(string $key) {
        static $definitions;
    
        if (isset($definitions[$key])) {
          return $definitions[$key];
        }
      }
    }


    The $definitions in return $definitions should not be highlighted here, right?

      24 days later

      Murz we underline the variable because there is no assignment to it. So it does not make any sense; it's always unset.

        JakubMisek but it's static, so can be not empty after the definition.

          Murz but it's never initialized, it's NULL always.

            JakubMisek There was only a part of the full function, in the full function the initialization happens later. And I see that with the latest version the error got disappeared in my code, so seems something is fixed in this area. Thanks!

              Murz thank you for the update, it makes sense now. I'm glad it works for you now.

                Write a Reply...