Is there a well-established naming convention for PHP namespaces? Is there a well-established naming convention for PHP namespaces? php php

Is there a well-established naming convention for PHP namespaces?


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:

https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md


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_naming_standards

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.


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.