A
A
Andrey Ivchenkov2016-03-18 15:20:25
PHP
Andrey Ivchenkov, 2016-03-18 15:20:25

How to tell phpDoc that a variable is just a class?

There is this code:

class app\models\Product{
         public static getSomeClass($modelType){
                  if ($modelType=='MyClass1'){
                      return 'app\models\MyClass1';
                  } else{
                      return 'app\models\MyClass2';
                  }
         }
}

class app\models\MyClass1{
         public static function sayHello(){
                  echo 'Hello';
         }
}

$instClass = Product::getSomeClass('MyClass1');
$instClass::sayHello();

Accordingly, the IDE does not understand that $instClass is the class MyClass1, and autocomplete for $instClass does not work. How to tell the IDE that $instClass is the class MyClass1?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Ivchenkov, 2016-10-20
@Groonya

No way((

M
mistergonza, 2016-03-18
@mistergonza

/**
@return User
*/
public static getUserClass(){
...
}

A
Andrey, 2016-03-18
@VladimirAndreev

/** @var MyClass1 $instClass */
$instClass = Product::getSomeClass('MyClass1');

F
From_Earth, 2016-09-30
@From_Earth

/**
 * @return MyClass1 | MyClass2
 */
public static getSomeClass($modelType){
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question