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 196564 - Allow "@return this" to support method chaining in subclasses
Summary: Allow "@return this" to support method chaining in subclasses
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.0
Hardware: All All
: P3 normal (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-11 01:29 UTC by dharkness
Modified: 2013-01-30 03:42 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dharkness 2011-03-11 01:29:42 UTC
Currently you must specify the class as the return value for a chained-method (a method that returns $this). This breaks code completion when subclasses are involved.

class Parent {
    /**
     * @return Parent
     */
    public function foo() {
        return $this;
    }
}

class Child extends Parent {
    /**
     * @return Child
     */
    public function bar() {
        return $this;
    }
}

$c = new Child();
$c->           // CC shows foo() and bar(), correct
$c->foo()->    // CC shows only foo(), but I want bar() too

I would like to be able to set both @return attributes above to "this". NetBeans should be able to see that in the last line foo() returns $c which is a Child and display both methods in code completion.

I understand that this is not valid PHPDoc, but I see no reason to keep NB from extending it.
Comment 1 Tomas Mysik 2011-06-03 10:23:14 UTC
Batch reassigning.
Comment 2 Tomas Mysik 2011-06-03 10:32:35 UTC
Editor area.
Comment 3 BullfrogBlues 2012-02-09 10:02:52 UTC

*** This bug has been marked as a duplicate of bug 196565 ***
Comment 4 dharkness 2012-02-09 18:30:32 UTC
While this feature request is similar to 196565 in that it is asking for special handling of the @return doc comment, it's a different case. This one address fluent interfaces whereas the other is for static factory methods.
Comment 5 Ondrej Brejla 2013-01-15 10:19:09 UTC
reply to 1:
If foo() returns not just Parent, but sometimes Child too (if it's called on a Child type), then we should use "@return this" annotation instead of "@return Parent" (it's same as for @return static).

It doesn't work either by now, but I'll try to implement it.
Comment 6 Ondrej Brejla 2013-01-15 15:59:37 UTC
Fixed in web-main #f2368dd7777f
Comment 7 Quality Engineering 2013-01-30 03:42:04 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)