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.
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? <?php 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);
Created attachment 136181 [details] IDE log
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)
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.
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.
Confirming @return static annotation workaround for trait in 7.4 dev. Thanks