Identify php class for IDE

Say I have a function that returns an object of type SomeClass. And I have code like this:

$test = function_to_return_someclass(); 

Now I want to use the $ test variable in the IDE, but I want it to understand that $ test is of type SomeClass. I can do this easily with class variables using / ** @var * / comment, but this is where I am stuck. And so, having tried something like:

 $test = (SomeClass)function_to_return_someclass(); 

doesn't work, how can I instruct the IDE that $ test is a SomeClass object?

+4
source share
2 answers

You can try using @return in a function definition:

 /** * Generates an object of the class SomeClass * @return SomeClass the class */ function_to_return_someclass() { .... } 

it is up to your IDE whether it is enough to figure it out. It should be, however.

Second approach: Try

  /** * My object. Recognize it already, damn IDE! * @var SomeClass */ $test = function_to_return_someclass(); 
+4
source

You may try:

 /** * @return ClassToBeReturned */ function_to_return_someclass() {} 
0
source

Source: https://habr.com/ru/post/1314536/


All Articles