开发者

php class identification for IDEs

Let's say i have a func开发者_如何学JAVAtion 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 an IDE, but i want it to understand that $test is of type SomeClass. I can do it easily with class variables by using the /** @var */ comment, but this is where i get stuck. And since trying something like:

$test = (SomeClass)function_to_return_someclass();

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


You could try using @return in the function definition:

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

it's up to your IDE whether it's smart enough to understand it. It should, though.

2nd approach: Try

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


You could try:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜