phpstorm namespace functionalitie

Hello,

I'm new to phpstorm after using netbeans for a while.
phpstorm feels great to use, but i do find the namespace usage bugy.

Excample :
i have several files whit diverent classes under a namespace like

//File 1
namespace Name1\Name2\name3\Name4
{
    class ClassName1
    {
        // functions and code
    }
}

//File 2
namespace Name1\Name2\name3\Name4
{
    class ClassName2
    {
        // functions and code
    }
}

If i want to call these classes in a othe file i have to write in phpstrom (to get no errors)
use namespace Name1\Name2\name3\Name4\ClassName1;
use namespace Name1\Name2\name3\Name4\ClassName2;

$class1 = new ClassName1();
$class2 = new ClassName2();


So i have to write for each class a use line.
Normaly i did this :
use namespace Name1\Name2\name3\Name4; // or use some aliasing

$class1 = new Name4\ClassName1();
$class2 = new Name4\ClassName2();

But this is giffing me arror in phpstorm

also if i get the namspace names using intelicense, and hit tab or enter i get the full namespace path when calling a namespace class lik this :
$class1 = new \Name1\Name2\name3\Name4\ClassName1\ClassName1();


I use the Mac version phpstorm 3.0.

Will this be fixed in version 3.5?
I realy hope, becouse i find this quit iritating :-)

2 comments

I use namespaces in 3.0 with no issue on Lunix.

use namespace Name1\Name2\name3\Name4; // or use some aliasing

$class1 = new Name4\ClassName1();

Should be
use namespace Name1\Name2\name3\Name4; // or use some aliasing

$class1 = new ClassName1();

This is assuming the path is Name1/Name2/name3/Name4/ClassName1

With that use
$class2 = new ClassName2();
Should also work.

Assuming its in the same namespace.

0

Hello Jeff,

If you dont use the full namespace includig the classname, you hav to use the last name space when loading the class.
(i used for excample Name1 .. as namespace names and ClassName1... as the classnames in a namespace)

like this
if the clasname is class1

and you dont do this
use namespace Name1\Name2\name3\Name4\class1;
but this
use namespace Name1\Name2\name3\Name4; // this is saving me from to write a use line for every class

you need to do this
$test = new Name4\class1();

The coding i use runs fine, but the intelisence from phpstorm is shoing me incorect errors, it wil turn 1 namespace name in red.

Greetings,
Eelco

0

Please sign in to leave a comment.