Quite often in PHP model code (at least in my own such code) there are direct references to MySQL table and field names, and since MySQL identifiers are for the most part case-insensitive I typically use the under_score naming convention to make those identifiers a bit more readable.
At the same time however, it seems that most folks use camelCase conventions when they create PHP class libraries, and I've been trying to do that, too.
On top of that, the PHP built-in functions themselves are inconsistent. Some of them use camelCase, others use under_scores, and others use C-style naming (for example "strtolower").
The result is that the code tends to be much less readable than I prefer, what with mixed camelCase, under_score, and C-style naming conventions showing up quite near each other in the code.
How are other folks dealing with this? Perhaps there's some way people have found to organize their work so that the different naming conventions tend not to appear quite so close to each other? Or perhaps there are class libraries that if used properly, tend to make things a bit cleaner? I know these discussions of style can get heated -- no need to go there, just some practical suggestions please!
As teresko says, MySQL names are case sensitive on *NIX platforms and insensitive on Windows. If you develop code to support both (as I do) then mixing your cases can cause huge headaches: for example, dump a database on Windows and restore it onto *NIX and all your cases are lost. We actually had to kludge code to detect and fix the cases in a dump just for this reason.
If you're free of Windows though it doesn't really matter what you use, as long as you keep it consistent.
When it comes to models & database tables, you can use:
For classes I would generally use CamelCases (beginning with upper case) and camelCases for methods (beginning with lower cases).
But, in fact, what counts is consistency and readability. It may be a good idea to follow naming conventions of some of the well known and widely implemented frameworks, such as Zend Framework (this one provides pretty precise guidelines as far as coding standard is concerned), but eg. Kohana may be also a good idea. Reinventing the wheel may not be the best idea ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With