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 218519 - Fix uses in current namespace results in PHP Warnings
Summary: Fix uses in current namespace results in PHP Warnings
Status: NEW
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.2
Hardware: All All
: P3 normal (vote)
Assignee: Ondrej Brejla
Depends on:
Reported: 2012-09-18 09:49 UTC by dagguh
Modified: 2012-09-18 11:55 UTC (History)
0 users

See Also:
Exception Reporter:

IDE log (556.39 KB, text/plain)
2012-09-18 09:50 UTC, dagguh

Note You need to log in before you can comment on or make changes to this bug.
Description dagguh 2012-09-18 09:49:54 UTC
namespace some/package;

interface Listener {
     * @param \legacy_package_Request
    function handle(\legacy_package_Request $request);    


Now let's use "Fix uses in current namespace" (CTRL-SHIFT-I) with default suggestions.
By default NetBeans suggests to import \legacy_package_Request
This is the result:

namespace some/package;

use legacy_package_Request;

interface Listener {
     * @param legacy_package_Request
    function handle(legacy_package_Request $request);    


In runtime we recieve a PHP Warning:
PHP Warning:  The use statement with non-compound name 'legacy_package_Request' has no effect in **** on line 4
NetBeans should either import it as "use \legacy_package_Request;" or not import it at all (and leave all occurences unmodified).

Product Version = NetBeans IDE Dev (Build 201209110001)
Operating System = Linux version 3.2.0-31-generic-pae running on i386
Java; VM; Vendor = 1.7.0_07
Runtime = OpenJDK Client VM 23.2-b09
Comment 1 dagguh 2012-09-18 09:50:01 UTC
Created attachment 124496 [details]
IDE log
Comment 2 Ondrej Brejla 2012-09-18 10:58:17 UTC
If I run that code, no warning is shown (so it probably depends on a log level, or maybe PHP version?).

That leading namespace separator for fixed use statements is handled by the option - Tools->Option->Editor->Formatting->PHP->Uses->Start Use Statements with a Namespace Separator. So you can choose what to use.

Maybe we can add some new option, something like "Don't Use Types from Default Namespace"...or something like that, which will not import these types, or something better and different, but it's definitely enhancement for next release.

Thanks for catching that!
Comment 3 dagguh 2012-09-18 11:55:35 UTC
Our PHP version is 5.3.8
It is reproducible with error_reporting(E_ALL)

If I check "Start Use Statements with a Namespace Separator", all uses start with it:

use \some\package\Listener;
use \legacy_package_Request;

new legacy_package_Request();
For some people this is the standard, for others it isn't.

People who prefer use statements without the trailing backslash (like me), should only check "Prefer Fully Qualified Names over Use of Unqualified Names". It basically achieves my second suggestion from initial comment:
(In reply to comment #0)

> NetBeans should (...) not
> import it at all (and leave all occurences unmodified).

use some\package\Listener;

new \legacy_package_Request();