Search code examples
phpdocumentationphpdocdoc

Should I use @return self, this or the current class?


I have a method that return the current object, how do I document this?

/**
 * set something
 *
 * @return this
 */
public function setSomething(){
            // ...
    return $this;
}

Or should I do @return self or @return Current_Class_Name?


Reason why this question is not "primarily opinion-based" (and should be reopened): conformance to standards and IDE type hinting support.


Solution

  • @return Current_Class_Name will definitely work and is what I prefer.

    @return self may work ok with some programs too.

    @return this is bad because this is not a typename.