Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP docBlock @return className

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)

like image 506
Mathias Bosman Avatar asked Mar 17 '12 16:03

Mathias Bosman


1 Answers

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.

like image 127
jpic Avatar answered Sep 20 '22 01:09

jpic