Usually namespaces follow the same naming conventions as the folder structure. I don’t know what you’ve have planned for the folder naming conventions in yii2 but I think that it would be great if it followed the same naming conventions as it’s predecessor. In other words it would be something like:
Many projects use a /src folder now to store their PHP classes, usually the autoloader maps this directory.
I think your example applies for the application directory (currently “protected”), “public” files are separated anyway and don’t have to follow these conventions.
At the moment I can think i.e. example of uploaded data and non-PHP scripts which go also into “protected”, but maybe it’s time to refactor the protected structure.
I know that the existing one is a very slim implementation and very useful for running your app out-of-the-box from your default webserver root, but I won’t sacrifice so much for it.
@schmunk: This has nothing to do with "protected" or "src".
How would you name your view files and view directories? And what about data directories, etc.?
@Chris83: The current implementation of Yii 2 uses the namespace format like you wrote (same as Yii 1.1). Here we are debating whether we should adopt CamelCase in namespace in Yii 2. So far, I’m most concerned with the mixed use of cases in directory names: class directories use CamelCase, while non-class directories use lower-case, which doesn’t look good to me.
Does PSR-0 require the folders containing classes are named using CamelCase? If not, I’d like to keep it as it is currently in Yii, I’m not too fond of the namespace naming conventions used by Zend2 and Symfony2.
@Qiang: I don’t think Yii 2 should use CamelCase for namespaces unless it’s absolutely necessary. I share your concerns in this matter.
Is there another (larger) project which uses headlessCamelCase for namespaces?
IMHO it would be really annoying, when working with namespaces in Yii2, that the namespace syntax would be mixed all the time.
$obj = new \yii\base\Object();
$foo = new \Another\Base\Object();
use Composer\Script\Event;
use yii\console\script\Event;
use \Monolog
use \yii\log\Logger;
I wonder if namespaces in lowercase are really such a big issue. If uppercase namespaces require us to have some directory names start with an upper case letter then we should really avoid them. On linux systems (which most of us will use for professional hosting) it’s very unusual to have such a directory name. And they are more inconvenient to type.
I’m not totally against using CamelCase in namespace because it has its pros as you explained.
But I’m very bothered by the inconsistent naming in directories, and also as Mike wrote, it’s uncommon to use upper case in directory names.
@schmunk: even if the directories are organized as you proposed, there are still cases that directories are named differently under the same directory, which is confusing. And another minor issue is: should the names be plural or not.
I’m still for camelHump namespaces and folder names. I don’t think that it’s a problem if Symfony components use different naming conventions.
Besides I like the current folder naming conventions in Yii, both the casing and plural form. I kind of dislike the CamelCase singular directory names, it feels a bit less natural.
IMO adding a convention that uses UpperCase directory names if the folder contains classes and lowerCase if not adds some unnecessary confusion when you create directories.
On file systems that are case sensitive it may cause more problems than before. I’ve seen many people deploying code from a windows machine to a linux server and wondering why it did not work there.
I haven’t heard really good arguments except “All the other do it like this.” for CamelCase namespaces…
I think we can agree that namespaces should reflect the directory structure and so lowerCase directory names will result in lowerCase name spaces. As Mike pointed out it is very uncommon to name directories in CamelCase on a linux system. On a terminal to create a directory or to go into you always have to remember to type the right case when you want to enter a directory. This is a bit annoying when you have CamelCase but even more when you have a mixed structure.
Unless there is a really good reason we should not use a possibly confusing convention.
Btw, Müller: Why is "Resource"-directory UpperCase in your example? it does not contain any classes…