Custom class detection

There is special function in our project which takes class name as argument and return instance of this class. And PHPStorm can't determine, of which class this instance is.
$c = class( 'test' ); // $c - instance of class test.
In this case PhpStorm can't determine that $c - is instance of test class and code completition desn't work.
Is there any opportunity to say to PHPStorm, that argument of function 'class' is a class name and result of function invocation is instance of this class? It's needs for method/fields detection and code completion.
Thank you.

Comment actions Permalink

Hi there,

Few choices:


/** @var test $c */

$c = class( 'test' );

2) Install and use DynamicReturnType plugin

3) and related some tickets

4) If you could replace your class() function by some static class (e.g. Factory::make() or whatever you will name it) then such approach is already supported:

Comment actions Permalink

Ок, thank you, Andriy.


Please sign in to leave a comment.