0

What's the exact difference between these two things?

I find myself, as if on autopilot, writing the filesystem path at the top of each php file after the word namespace.

Because this feels a bit redundant, I wonder if I'm doing it right.

mwal
  • 2,803
  • 26
  • 34
  • Not clear exactly what you mean - can you show some code? Having your namespace match your filesystem makes for easy autoloading of classes. – wogsland Sep 14 '16 at 15:50
  • The use operator is for giving aliases to names of classes, interfaces or other namespaces...and has actually got nothing to do with the file structure directly. Take a look at this answer [php-namespaces-and-use](http://stackoverflow.com/questions/10542012/php-namespaces-and-use) – B001ᛦ Sep 14 '16 at 15:51
  • Typing out namespaces is tedious, I agree. I'd recommend using an IDE such as PhpStorm to have that sort of tedium automatically handled for you. – Hayden Schiff Sep 14 '16 at 15:51
  • Thanks @hayden, that's the quick answer I needed at this point. – mwal Sep 14 '16 at 16:00
  • If using sublime text, php companion plugin offers a "find use" command, which can add the use statement automatically for you, as Hayden suggests. – mwal Sep 16 '16 at 11:51
  • And an even better (though tangential) answer to my original question: php companion also has an "import namespace" function which does for you what I was doing longhand: https://github.com/erichard/SublimePHPCompanion – mwal Sep 16 '16 at 11:57

0 Answers0