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 231678 - Referencing function in wrong class when trait used in one of the classes
Summary: Referencing function in wrong class when trait used in one of the classes
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.3
Hardware: All All
: P4 normal (vote)
Assignee: Ondrej Brejla
Depends on:
Reported: 2013-06-23 10:52 UTC by berniev
Modified: 2013-07-26 08:52 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:

IDE log (64.10 KB, text/plain)
2013-06-23 10:52 UTC, berniev

Note You need to log in before you can comment on or make changes to this bug.
Description berniev 2013-06-23 10:52:46 UTC
Product Version = NetBeans IDE Dev (Build 201306212301)
Operating System = Linux version 3.0.0-32-generic-pae running on i386
Java; VM; Vendor = 1.7.0_21
Runtime = OpenJDK Client VM 23.7-b01

My code or bug?


trait Singleton {

	public static function GetInstance() {
		static $tInstance = null;

		if (!$tInstance) {
			$class = __CLASS__;
			$tInstance = new $class;
		return $tInstance;


class AnotherTest {

	private $here;

	public function Afunction() {
		$this->here = 'AnotherTest';
		return $this->here;


class Test {

	use Singleton;

	private $here;

	public function Afunction() {
		$this->here = 'Test';
		return $this->here;


$fred = Test::GetInstance();
$res = $fred->Afunction(); // <==== hover, Ctrl-Click on Afunction()
var_dump($fred, $res);

 * Very confusing..
 * result indicates $fred becomes an instance of Test as expected
 * But hover over the function call Afunction() and Ctrl-Click
 * takes cursor to Afunction() in AnotherTest
 * instead of Afunction() in Test
 * Commenting out the 'use' line and swapping the order of the class definitions
 * it moves the cursor to whichever class is defined first, 
 * but of course produces a fatal error when run
 * With 'Use' line commented out hover, Ctrl-Click on the following 
 * seems to remember which class it was pointing to last time.
$fred = new Test;
$res = $fred->Afunction(); // <==== hover, Ctrl-Click on Afunction()
var_dump($fred, $res);
Comment 1 berniev 2013-06-23 10:52:55 UTC
Created attachment 136181 [details]
IDE log
Comment 2 Ondrej Brejla 2013-06-24 08:42:18 UTC
Sorry, I copy&pasted your code and ctrl+click on both method calls ($fred->Afunction();) puts me to Test::Afunction(). And it is correct.

Product Version: NetBeans IDE Dev (Build 20130624-c291fe2c677d)
Java: 1.7.0_25; Java HotSpot(TM) Client VM 23.25-b01
Runtime: Java(TM) SE Runtime Environment 1.7.0_25-b15
System: Linux version 3.8.0-25-generic running on i386; UTF-8; cs_CZ (nb)
Comment 3 Ondrej Brejla 2013-06-24 08:45:48 UTC
There is another problem. If I click on AnotherTest::Afunction() declaration BEFORE clicking on method calls, occurences are marked wrongly (it's paired with the first method call). But it's reseted if another occurence is marked before clicking on method invocation. I'll look at it, but not sure about fix :/ We will see.
Comment 4 Ondrej Brejla 2013-06-24 09:20:52 UTC
We are not able to determine the return type of GetInstance method form code right now, but you can use:

 * @return static
public static function GetInstance() {}

@return static annotation and then it will work. But it's a new feature in 7.4, so it will not work in 7.3.

For me it's almost impossible to detect method return type from the code inside it. It's simple in some "return new Foo()" cases and such, but for these instantiation of variables, it's almost impossible.

So for me it has a simple workaround... But I'll not close this issue, I'll leave it as P4. Maybe somedays it will have another solution (but I don't think so, it's really hard to do such a complex evaluation of code). Thanks.
Comment 5 berniev 2013-07-26 08:52:53 UTC
Confirming @return static annotation workaround for trait in 7.4 dev.