views:

161

answers:

5

So far, I've seen many different naming conventions used for PHP namespaces. Some people use PascalCase\Just\Like\For\Classes, some use underscored\lower_case\names, some even use the Java convention for package names: com\domain\project\package.
The question is very simple -- can any of these (or other) conventions be called well-established? Why? Are any of them recommended by authorities like Zend or the developers of well-known PHP frameworks?

+1  A: 

The recommended naming guide is here.

dnagirl
It doesn't seem to say anything about namespaces, however...
Ignas R
+1  A: 

Personally I like writing classnames upper camelcase, class attributes and methods lower camelcase and class attributes prefixed with an underscore.

Other local variables i'm also writing lower camelcase without an underscore prefix. Object instances are always written uppper camelcase etc. etc. I don't really think that there is a best way, you just have to be consistent to your codingstandard. This gives you the advantage of reading faster through your code and it should give a faster insight in what's happening at which codelines.

Ben Fransen
A: 

Also have a look at Zend's and Pear's naming guide:

http://framework.zend.com/manual/en/coding-standard.naming-conventions.html

http://pear.php.net/manual/en/standards.naming.php

eyazici
Doesn't say anything about namespaces though.
troelskn
Naming guide does not means namespace, also namespace concept is very immature for PHP world.
eyazici
Uhm .. but the question was about namespaces.
troelskn
+1  A: 

I don't think you can say there is anything well established at this point, but there is an RFC discussing it for PEAR2: http://wiki.php.net/pear/rfc/pear2%5Fnaming%5Fstandards

My take is that namespaces are a form of variables, and therefore should follow the same convention as they do. I genereally prefer lowercase_underscore for free variables (As opposed to object members), so the most natural for my taste would be namespace\ClassName. This also matches the most prevalent conventions from other languages. On the other hand, the same argument could be made for pre-5.3 pseudo-namespaces, but here the de-facto standard seems to be using CamelCase.

troelskn
+1  A: 

A PHP Standards Working Group made up of contributors to many different PHP frameworks and projects came up with the following proposal for appropriate namespace usage:

http://groups.google.com/group/php-standards/web/psr-0-final-proposal

Ben Ramsey