How do I mark a method as \"returns an instance of the current class\" in my phpDoc?
In the following example my IDE (Netbeans) will see that setSomething always returns
Update:
As of Netbeans 7.4, the IDE supports @return self, static, and this (http://wiki.netbeans.org/NewAndNoteworthyNB74#Editor_2).
class foo {
protected $_value = null;
/**
* Set something
*
* @param string $value the value
* @return this
*/
public function setSomething($value) {
$this->_value = $value;
return $this;
}
}
class bar extends foo {
public function someOtherMethod(){}
}
Previous Answer:
We have a similar issue with a record iterator's current()
method. Since the iterator is extended for many different classes, it doesn't make sense to have a @return $class
associated with it. We've used @satrun77's Option 2 before, but I've used @method with some success in Netbeans.
class foo {
protected $_value = null;
/**
* Set something
*
* @param string $value the value
* @return foo
*/
public function setSomething($value) {
$this->_value = $value;
return $this;
}
}
/**
* @method bar setSomething($value)
*/
class bar extends foo {
public function someOtherMethod(){}
}