I am seeing more and more extensions for Yii that use “C” for prefixing their class names. I won’t mention any specific ones, but there are a number of them, there’s no doubt about that.
All classes in Yii are prefixed with “C” in an attempt to avoid, or at least lessen the chance for, name collisions in PHP below version 5.3 (since it doesn’t have support for namespaces). As far as I know this is not an official reservation/convention, but it is mentioned in the Guide (at http://www.yiiframework.com/doc/guide/1.1/en/basics.convention#code) as follows:
In my opinion, noone writing Yii code should use “C” as the first character in their class names, unless it’s the start of a word (i e the next letter is lowercase, in which case the C is not a prefix). The reason for this is to let Yii core classes use “C” as their prefix, both to make room for future classes and to make it easier to distinguish custom/non-Yii classes and Yii classes. It could also make the convention clearer.
When writing extensions, I suggest we use “E” as the prefix, or a prefix that is an abbreviation of the author’s name or something like that. Anything but what the Yii core uses, at least.
Yii core developers; Can we make this not just a recommendation but a formal convention? I mean that C is reserved for Yii core classes and should not be used by others, such as extensions.
Also, if anyone else than me feel this question/issue is of some importance, would it be a good idea to pin this topic to the top of the subforum, så that extension developers see it when browsing here?
Or maybe even better, make a new paragraph in the Convention section in the Guide, named "Extensions", in which some key rules for extension development are explained.
Agree. Unfortunately even some popular extensions use the “C” prefix. Shouldn’t we have a big red note about this on the page where you can submit your extension?
I totally agree! A bit off-topic, but also related (to not to open a new thread). What piece of software you (and others) would suggest as good and tested for professional Yii Extensions’ code documentation? What is used to document core Yii, etc.?
I can’t speak for Yii officially, but the two main points for me are; 1) Dont use “C” as the prefix. 2) Do use a prefix, so that non-prefixed class names can be used for components/extending classes (for example FooBar when we extended CFooBar, this way it’s really clear that the class in question is just a wrapper for the main one).
If you don’t have any specific prefix you’d like to use (for example your initials or an abbreviation for your company name), I’d default to “E”.
As there where still some new extension that did not follow the guidelines I just unpinned this topic and created a new one so that the main guidelines are more visible