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 242829 - Add support for @return static[] and @return self[] type hinting
Summary: Add support for @return static[] and @return self[] type hinting
Status: NEW
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.0
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-12 13:38 UTC by efbiaiinzinz
Modified: 2014-03-12 13:38 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 efbiaiinzinz 2014-03-12 13:38:54 UTC
class A {
	public $A = 'A';
	/**
	 * @return static
	 */
	public static function foo() {
		return new static();
	}
	/**
	 * @return static[]
	 */
	public static function foos() {
		return [new static()];
	}
	/**
	 * @return A[]
	 */
	public static function foosA() {
		return [new static()];
	}
}
class B extends A {
	public $B = 'B';
	/**
	 * @return \static
	 */
	public static function boo() {
		return new static();
	}
	/**
	 * @return static[]
	 */
	public static function boos() {
		return [new static()];
	}
}
A::foo()->A;//->A is offered in autocompleter
B::foo()->A;//->A is offered in autocompleter
B::foo()->B;//->B is offered in autocompleter
foreach (A::foosA() as $foo) {
	$foo->A;//->A is offered in autocompleter
}
//following variable cases are NOT shown in autocompleter
foreach (A::foos() as $foo) {
	$foo->A;//->A is NOT offered in autocompleter
}
foreach (B::boos() as $boo) {
	$boo->A;//->A is NOT offered in autocompleter
	$boo->B;//->B is NOT offered in autocompleter
}

As seen from the simple testcase:
- typehint @return static works correctly (same goes for @return self but did not include sample to keep things short)
- typehint @return A[] also works correctly for the foreach case
- typehint @return static[] is not detected correctly, foreach block does not detect A::foos() as array of A instances and does not detect B::boos() as array of B instances

Since the static and self return types are supported and ClassName[] notation is also supported, it would be good to have support for static[] hinting.