Reputation: 69
Is there a naming convention for file classes and properties regarding Many-To-One / One-To-Many relations. This might sound like a classic question on naming concention but this is not, it's a question applied to relations, let's say in Doctrine for example.
This might be silly but names are quite important, aren't they?
In this case, I have an entity GolferProfile
, an entity Category
, and therefore want an intermediate GolferProfile-Category
entity.
What class name should I use for the intermediate entity?
GolferProfileCategory OR GolferProfile_Category OR GolferProfile-Category OR anything else?
Same with the property...I have seen people using the first letter of each class, which would be $gc
in this case. This is pretty much difficult to read, but on the other hand we don't want to work with a long name like $golferprofile_category
?
Any thoughts on this would help me to understand how to work with names..Cheers
Upvotes: 3
Views: 294
Reputation: 72652
class GolferProfile-Category {}
produces a syntax error.
GolferProfile_Category {}
The underscore will be replace by a directory separator in PSR-0.
GolferProfileCategory {} // is the winner.
Same with the property...I have seen people using the first letter of each class, which would be $gc in this case. This is pretty much difficult to read, but on the other hand we don't want to work with a long name like $golferprofile_category?
$gc
is a terrible name. Nobody would know what that means. If you are referring to the variable which is an instance of the class I always go for camelCase.
$golferProfileCategory
And in my experience most people (at least in PHP) do it this way.
Upvotes: 2
Reputation: 16585
There is no rule of thumb, but I would recommend sticking to a single practice when it comes to naming conventions for everything: you seem to be using camelCase already, so why not use it for everything else?
GolferProfile
Category
GolferProfileCategory
$golferProfile
$category
$golferProfileCategory
Upvotes: 3
Reputation: 31
Considering PHP is a C-like language, I would follow its doctrine.
Reference: http://www.psgd.org/paul/docs/cstyle/cstyle04.htm
Upvotes: 3