Search code examples
phpphpstorm

Static class vars type definition in PhpStorm


I have some class named myClass, and following structure in there:

class myClass
{
    static $foo;

    public static function init()
    {
        self::$foo = new bar();
    }
}

How can I make phpstorm define myClass::$foo as bar's object in the rest of my code?


Solution

  • Use a PHPDoc.

    class myClass
    {
        /**
         * @var bar $foo - Holds a bar object.
         */
        static $foo;
    }