PHP docBlock @返回className [英] PHP docBlock @return className
问题描述
如何创建一个PHP DocBlock,声明一个@return,它声明一个类的返回.这样做很简单
How do I create a PHP DocBlock stating an @return which states the return of a class. This is at the moment fairly simple by doing
/**
* This returns an object of the "User" class
* @return User
*/
public function getUser() { return $this->user; }
我用它来通过我的IDE获取这些返回值的智能感知. (在我的情况下是Netbeans)
I use this to get intellisense through my IDE for these return values. (in my case Netbeans)
但是我有一个基于变量名返回类的类. (例如:)
However I have a class that returns a class based on a variable name. (for example:)
/**
* This returns an object of the $param
* @param String $className
* @return ???
*/
public function getSomeObject($className) { return new $className(); }
我也在尝试为此创建智能感知,但是我不确定这是否真的可能.
and I'm trying to create intellisense for this aswell but I'm not sure if this is actually possible.
例如,当我打电话
$someClass = new MyClass();
$var = $someClass->getSomeObject('Address');
我希望我的IDE向我展示变量$ var(将包含地址对象)的智能感知
I would like my IDE to show me intellisense for the variable $var(which will contain an Object of Address)
推荐答案
除非您可以列出 all 个潜在的回报类型,否则
Unless you can list all the potential return types,
@return User|Address|Sandwich|Coiture
, 和 IDE能够自动完成从聚集聚集 所有方法/属性的功能整个课程列表,那么我看不到它.
, and the IDE be capable of allowing autocompletion to aggregate all methods/properties from that entire list of classes, then I don't see it as possible.
这篇关于PHP docBlock @返回className的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!