Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Class Namespace Guidelines?

Go to End

9 Posts   1937 Views


21 July 2010 at 2:00am Community Member, 13 Posts

I'm new w/ SilverStripe and I've encountered problems w/ class namespacing. I was following the tutorials in the book "Silverstripe The Complete Guide to CMS Development" and got this error:

Warning: There are two files both containing the same class: 'C:\wamp\www\silverstripe/mysite/code/Member.php' and 'C:\wamp\www\silverstripe/sapphire/security/Member.php'. This might mean that the wrong code is being used. in C:\wamp\www\silverstripe\sapphire\core\ManifestBuilder.php on line 461

Maybe atleast silvestripe can implement guidelines w/ it especially when creating new modules to avoid the said error.


21 July 2010 at 2:11am Forum Moderator, 1796 Posts

no no - the code in sapphire/core/ManifestBuilder.php works - my guess is that you have created this Member.php file and it contains

class Member ...

and silverstripe is rightly going to insist that you have only one Member class. Are you trying to "Decorate" the member class?


21 July 2010 at 4:54pm Community Member, 13 Posts

For example I'll create a new module let's say "Google". Then there'll be a Map.php class. Then another developer is creating another module "Yahoo". The developer might also create a Map.php class. So there's a conflict and to prevent it, GoogleMap.php class and YahooMap.php class are advisable naming convention.

As I can see with Silverstripe's package modules like cms, it doesn't follow the said convention above. And the chance of class naming conflict is high.


21 July 2010 at 5:41pm Forum Moderator, 1796 Posts

I disagree I have built several larger than average functionality sites and only had this issue once when I wanted to name a file/class Session.php in the end I should have gone for BookingSession which was a better name.

In general [programming hat on] you should give things as desciptive names as possible - so using 2/3 words for each and say there is a conflict because you want a Car DataObject and a Car ModelAdmin... well they clearly should not both be called Car.php...


21 July 2010 at 6:41pm Forum Moderator, 5511 Posts

We don't have any specific guidelines for modules etc but for core libraries if a class is likely going to conflict (such as Datetime) it should be named spaced with SS_.

For modules which need classes like 'Map' really its the responsibility of the module author to come up with a practical name such as GoogleMap.php etc.

We also encourage the usage of naming a class with what functionality it provides which makes it clearer for developers and reduces conflicts such as


To define classes for those.

For decorating members I normally do class it something like ForumMember (where Forum is the name of the module which it appends it to) or SiteNameMember (where Site name is the name of your site).

If you would like this documented more strictly I would be happy to provide a wikipedia to help you decide. Add it as a documentation request on


21 July 2010 at 6:45pm Community Member, 13 Posts

Yeah! It's true that's my main point (descriptive class name) like my example above. So what's the good class name for Car DataObject and a Car ModelAdmin? You had even experience that problem and as a newbie I would like to read some guidelines on it. :)

And oh yeah I would like to see Silverstripe on PHP 5.3 utilized namespace feature. Are there already actions on it?


21 July 2010 at 6:50pm Forum Moderator, 1796 Posts

For Car DataObject I tend to use Car.php because it defines a Car.
For Car ModelAdmin I use CarAdmin.php (which then contains the controller) because it administers the 'Cars'.


21 July 2010 at 6:52pm Community Member, 13 Posts

Yeah it would be better if we have the wiki for this. :)

Thanks Willr!

Go to Top