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.
Phpdoc "@return this" works fine when you dont use namespaces. When use namespace, works only if add backslash at beginning of keyword "@return \this". Keywords shouldn't be namespace dependant. Here is example code: namespace test; class A { /** * @return this */ public function foo() {} } class B extends A { /** * @return this */ public function boo() {} } namespace test2; $obj = new \test\B(); $obj->boo()-> // no suggestions here With backslash work as should: namespace test; class A { /** * @return \this */ public function foo() {} } class B extends A { /** * @return \this */ public function boo() {} } namespace test2; $obj = new \test\B(); $obj->boo()->foo()->boo()->foo()-> // works fine
"this" is not keyword and can't work that way you described, because one can declare a class (or any other type) which will be called "this". This is valid php program: <?php class this { function __construct() {echo "OK";} } new this(); ?>
The only thing which could probably works is "@return $this", but it has to be implemented, it never worked. It's an enhanecement.
You are right, "this" can not be keyword, but workaround with "@return \this" really work at the moment. Also, I think, code completion should have same behavior if method contains code "return $this;" without any phpdoc. But at the moment, it works like "@return self": namespace test; class A { public function foo() { return $this; } } class B extends A { public function boo() { return $this; } } namespace test2; $b = new \test\B(); $b->boo()->foo()-> // CC has only method "foo" here, but should have both "boo" and "foo" Should I make new enchancement request for this?
You can but imho it's not necessary. It will not be easy to fix, because $this depends on runtime, but return types in IDE are solved "statically", IDE really don't and can't know what will be the exact type of "$this" in runtime.
I have fiew other notices, that might help to solve the problem: phpdoc "@return static" have close to same behavior as "@return $this" should. namespace test; class A { /** * @return static */ public function foo() { } } class B extends A { /** * @return static */ public function boo() { } } namespace test2; $b = new \test\B(); $b->boo()->foo()->boo()->foo()->boo()->foo()-> // works fine! But if you add "return $this;" in methods, looks like phpdoc and return statement start to conflict: namespace test; class A { /** * @return static */ public function foo() { return $this; } } class B extends A { /** * @return static */ public function boo() { return $this; } } namespace test2; $b = new \test\B(); $b->boo()->foo()-> // sometimes only "foo", sometimes "no suggestions", sometimes both "foo" and "boo" Because of that conflict, I tried to use "@return this" phpdoc and found "@return \this" workaround. I understand that "return $this;" has much complex behavior than phpdoc "@return static", but it will be better than what we have at the moment, if they'll have same behavior for code completion.