Home arrow PHP arrow 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.

  1. PHP Application Development Part One
  2. Directory structure
  3. File naming conventions
  4. Coding conventions
  5. PHP coding conventions
  6. Conclusion
By: David Fells
Rating: starstarstarstarstar / 106
March 01, 2005

print this article



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.

>>> More PHP Articles          >>> More By David Fells

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: