假设我有一个返回SomeClass类型对象的函数.我有这样的代码:
$test = function_to_return_someclass();
现在我想在IDE中使用$test变量,但我希望它能理解$test是SomeClass类型.我可以使用/ ** @var * / comment轻松地使用类变量来完成它,但这是我被卡住的地方.尝试类似以下内容:
$test = (SomeClass)function_to_return_someclass();
不起作用,我怎么能指示IDE $test是SomeClass的对象?
解决方法:
您可以尝试在函数定义中使用@return:
/**
* Generates an object of the class SomeClass
* @return SomeClass the class
*/
function_to_return_someclass()
{
....
}
这取决于你的IDE是否足够聪明才能理解它.不过应该这样.
第二种方法:
尝试
/**
* My object. Recognize it already, damn IDE!
* @var SomeClass
*/
$test = function_to_return_someclass();
标签:php,casting
来源: https://codeday.me/bug/20190627/1299554.html