tags:

views:

364

answers:

4

ok, im relatively new to php programming and have been plodding along quite unaware that it is possible to actually use namespaces in php as I can in c# etc.

Its really ugly though as they have decided to use backslashes - why!

Anyway, I am interested in other php programmers views on whether namespaces will catch on in php and whether I should begin to use them now?

+1  A: 

They will most likely not catch on until the core starts using them (in PHP 7 maybe possibly perhaps...), but using Python for a few months will show you that namespaces are AWESOME.

Ignacio Vazquez-Abrams
I don't think it will take that long. The major frameworks are already transitioning to namespaces. I'd say the main argument against namespaces right now (besides the backslash being dirt ugly) is the lacking availability of PHP 5.3 on shared hosts.
Gordon
@Gordon I agree with the availability of 5.3 on shared hosts - its pretty damm annoying and yes the backslash is really ugly for some reason. I have been trying to think why its so ugly but I cant seem to think exactly why - its really bad for some reason.
David
@David: It's already used in strings to give special meaning to some characters, or to escape quotes. We've had to double them for so long that seeing a single backslash offends our sensibilities.
Ignacio Vazquez-Abrams
@Ignacio yes i see where you are comming from - could it possibly be though that it so different to all the other c based languages?
David
The PEAR2 coding standards also mandate namespaces, and require a minimum version of 5.3 as a result. http://wiki.php.net/pear/rfc/pear2_standards
Charles
+1  A: 

Unless all your code runs on your own servers, it's too early to start using them as 5.3 is relatively new.

Other than that, I'm not sure if they will ever really catch on. Even classes took a long time to catch on with a large portion of the PHP programming population.

Aaron Harun
Do you not think it should be a 'best practice' that should be used though?
David
I'm not sure yet. I haven't played with it enough. In theory though, I'd say yes since PHP desperately needs namespaces to stop the proliferation of unreadably long function names.
Aaron Harun
5.3 was released in June 2009. That's a year ago now. "Relatively" new indeed.
Charles
It's practically newborn when you consider hosts are /finally/ moving away from PHP4 now.
Aaron Harun
A: 

I would start learning how to use namespaces as soon as possible. Zend Framework 2.0 will use namespaces, which will mean that anyone using PHP 5.2 or lower will be out of luck. I use a virtual dedicated server, so I can control my PHP version. If you use cPanel/WHM, you can install PHP 5.3 very easily. If you are on shared hosting, it may be a little bit before you see 5.3 installed, although there are 5.3 adopters out there.

webjawns.com
A: 

Its use is already catching on. A couple of projects use it in their upcoming/beta versions. Most examples I've seen however use it like a cargo cult. Doctrine2 for example uses five or more nested namespaces (code smell), probably to provide a 1:1 mapping of namespace/class to the filesystem/directories. I guess the novelty makes PHP namespaces prone to unreasoned overuse.

Anyway, the syntax doesn't help with readability that much. And it's a big turn off for professional programmers. But if there is a serious use case in your project, just go for it. (Hypothetical naming conflicts are not the best reason.)

mario