Reputation: 63
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; }
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.
For example when I call
$someClass = new MyClass();
$var = $someClass->getSomeObject('Address');
I would like my IDE to show me intellisense for the variable $var(which will contain an Object of Address)
Upvotes: 7
Views: 3217
Reputation: 6688
Unless you can list all the potential return types,
@return User|Address|Sandwich|Coiture
, 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.
Upvotes: 2
Reputation: 33420
It would make sense to mention that the method returns an object as such:
/**
* [...]
* @return object
*/
Eventually with some details as such:
* @return object Object of class $className
See the docs for @return.
Upvotes: 2