Bug 196565 - Allow "@return self" and "@return static" to support factory methods
Allow "@return self" and "@return static" to support factory methods
Status: REOPENED
Product: php
Classification: Unclassified
Component: Editor
7.0
All All
: P3 with 11 votes (vote)
: 8.0
Assigned To: Ondrej Brejla
issues@php
:
: 200773 225889 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-03-11 01:36 UTC by dharkness
Modified: 2013-04-11 10:10 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo