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 251045

Summary: Editor does not correctly resolve namespaces for traits
Product: php Reporter: satrogenum
Component: EditorAssignee: Tomas Mysik <tmysik>
Status: NEW ---    
Severity: normal CC: tarzan-de
Priority: P3    
Version: 8.0.2   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: Partial fix (for model)

Description satrogenum 2015-03-09 22:30:13 UTC
If I have a two traits in different namespaces with the same name, the editor does not correctly determine the trait to use: it seems to go in alphabetical order rather than using the current namespace.

Example:

--- FILE 1 ---

<?php

namespace ns1;

trait TestTrait {

    public abstract function foo();
}

--- FILE 2 ---

<?php

namespace ns2;

trait TestTrait {

    public abstract function bar();
}


--- FILE 3 ---

<?php

namespace ns2;

class TestClass {

    use TestTrait;

    public function bar() {}

}

The editor reports an error in file 3, that abstract function 'foo()' has not been defined. This seems to be because it is resolving the 'use TestTrait' statement as 'use ns1\TestTrait' rather than 'use ns2\TestTrait'. Trait names in a trait use statement are expressed relevant to the namespace of the class.
Comment 1 Tomas Mysik 2016-06-10 08:44:52 UTC
Taking over.
Comment 2 Tomas Mysik 2016-06-23 10:57:10 UTC
Unfortunately, this is very difficult to fix. Even if I fix the model part, the index part still (incorrectly in this case) uses both traits and there is no easy way to fix it (at least for now, at least for me).

Attaching partial fix for model.

Thanks for reporting.
Comment 3 Tomas Mysik 2016-06-23 10:58:32 UTC
Created attachment 160146 [details]
Partial fix (for model)

However, the index part is still broken.