This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 196565

Summary: Allow "@return self" and "@return static" to support factory methods
Product: php Reporter: dharkness <dharkness>
Component: EditorAssignee: Ondrej Brejla <obrejla>
Status: REOPENED ---    
Severity: normal CC: Inscure, po_taka, RiaD
Priority: P3    
Version: 8.0.1   
Hardware: PC   
OS: Windows 7 x64   
Issue Type: ENHANCEMENT Exception Reporter:

Description dharkness 2011-03-11 01:36:39 UTC
As a shorthand to specifying the name of the class in the @return PHPDoc attribute for a standard factory method, I'd like to be able to use "@return self". This wouldn't really add much benefit beyond supporting lazy fingers. :)

class SomeClass {
    /**
     * @return self
     */
    public static function create() {
        return new self();
    }
}

$c = SomeClass::create();
$c->    // CC shows methods from SomeClass

However, for static factory methods that use "new static(...)", it would be of great benefit to support "@return static".

class Parent {
    /**
     * @return static
     */
    public static function create() {
        return new static();
    }
}

class Child extends Parent { ... }

$c = Child::create();
$c->    // CC shows methods from both Child and Parent

I know this isn't part of the PHPDoc standard, but I think it would still be beneficial to those that would like to use it.
Comment 1 Tomas Mysik 2011-06-03 10:23:16 UTC
Batch reassigning.
Comment 2 Tomas Mysik 2011-06-03 10:32:14 UTC
Editor area.
Comment 3 Ondrej Brejla 2011-12-05 14:48:50 UTC
*** Bug 200773 has been marked as a duplicate of this bug. ***
Comment 4 BullfrogBlues 2012-02-09 10:02:52 UTC
*** Bug 196564 has been marked as a duplicate of this bug. ***
Comment 5 magnetik 2012-10-02 15:12:45 UTC
It would be really usefull as Factory is being more and more used.
Comment 6 Ondrej Brejla 2013-01-15 15:59:46 UTC
Fixed in web-main #f2368dd7777f
Comment 7 Quality Engineering 2013-01-30 03:42:14 UTC
Integrated into 'main-golden', will be available in build *201301300001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/f2368dd7777f
User: Ondrej Brejla <obrejla@netbeans.org>
Log: #196564 and #196565 - Allow "self", "static" and "this" in a @return annotation (improved type inference)
Comment 8 Ondrej Brejla 2013-02-08 12:41:13 UTC
*** Bug 225889 has been marked as a duplicate of this bug. ***
Comment 9 prenaudet 2013-04-11 10:10:05 UTC
Hi,
static work great on Dev build, but it will be nice to allow self[], $this[] and static[] too...

class classParent {
    public function funcParent(){}
    /** @return static */
    static public function create($array){
        //some Code
    }
    /** @return static[] */
    static public function createList($array){
        $return = array();
        foreach($array as $createArray){
            $return[] = static::create($createArray);
        }
        return $return;
    }
}

class classChild extends classParent {
    public function funcChild(){}
}

$childs = classChild::createList(array());
foreach($childs as $child){
    $child-> //CC shows methods from both classChild and classParent | but "No Suggestion"
    classChild::create($array)-> //CC shows methods from both classChild and classParent | That's good
}

Thank's taht will be really usefull.
Comment 10 Inscure 2014-10-13 19:41:10 UTC
This still does not work for Netbeans PHP 8.0.1 if parent and child class are in different namespaces.