HomePHP Page 3 - PHP Application Development Part One
File naming conventions - PHP
Settling for the "quick and dirty" solution often costs far more time than it saves. This is as true of PHP coding practices as anything else. In this first article in the series, you will learn practices that will save you time and headaches in the long run, and help you write better PHP code.
Once an appropriate directory structure is established, it’s time to consider file naming conventions. The directory structure above gives us obvious locations for our files but does not imply any sort of scheme for the names of the files themselves. When naming your files, it is of the utmost importance to give files meaningful names. If you have ever had to work through an existing system with poorly named files, you know how difficult it can be to figure out which files perform which functions.
The two most common conventions for file naming are “word separation” and “camel caps”. An example of word spacing would be a file named “new_member_signup.php”. An example of a file named with camel caps would be “newMemberSignup.php”. It is my opinion that camel caps is the appropriate convention in all situations and that neither files nor directories should begin with capital letters. Using this convention makes it easy to read file and directory names quickly and it is also simple to retype them, which is not the case when using word spacing.
It is also good to avoid file names that are redundant with the name of the directory containing them. You would not name a string function library “lib.string.php” and place it in the lib directory – if it is in the lib directory in the first place, you know that the file will be a function library – “string.php” will suffice. The same rule applies to class files, configuration files, etc. All in all, the conventions for the physical application are quite simple and easy to remember.