phpDocumentor: There needs to be a way to indicate the containing class in function docblocks without explicitly entering the name of the class

For example when implementing a singleton:

class Singly {
    /**
     * Get the instance
     * @return Singly
     */
    public static function getInstance() {
        // Some code here...
    }
}

The @return Singly could instead be @return this, @return static or @return self or something like that.

This would be most useful for traits, which I know you are not focused on right now, but also useful in general: What if you have a function which returns $this and extend the implementing class? Then the function really returns an instance of the extending class, and this would be really useful to be able to determine for IDE auto completion.

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 37 (24 by maintainers)

Commits related to this issue

Most upvoted comments

@DavidBruchmann I have this, for now:

/**
 * A generic singleton trait.
 *
 * @author Jens Riisom Schultz <ibber_of_crew42@hotmail.com>
 */
trait Singleton {
    /**
     * Get the singleton instance.
     *
     * @return static
     */
    public static function getInstance() {
        static $instance = null;

        if (!isset($instance)) {
            $instance = new self();
        }

        return $instance;
    }

    /**
     * Make the constructor private.
     *
     * @return void
     */
    private function __construct() {}
}