PHP Application Development Part One - File naming conventions (
Page 3 of 6 )
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.
| | Discuss PHP Application Development Part One | | | | | | | I really like this article. It provides a lot of great information on good PHP... | | | | | | I will respectfully disagree with your comments =) PHP is a remarkably fast... | | | | | | Nice work! I always love to see articles relating to coding practices. Good luck on... | | | | | | Perhaps that is where my true disagreement is. I for one think:
"She has a... | | | | | | I will be mentioning templates later in the series and discussing why you should... | | | | | | Extreme example but compare the following two - find $chartype in each:
"Not only... | | | | | | All right, you've convinced me. Placing the variables outside of the string is... | | | | | | 0verall, this was a great article for covering basic PHP coding conventions. The... | | | | | | Thanks for the reply. I agree that using underscores is an acceptable convention,... | | | | | | In your article you stated;
------
<?php
$obj = &new MyObject();
... | | | | | | Somehow I did forget to mention that was fixed in PHP 5 - could've sworn I had.... | | | | | | Right. Good article.
I've noted a small mistake though:
<quote>
for ($i = 0;... | | | | | | It was my understanding that unless an object contained lots of data, such as a huge... | | | | | | ...I just wish I'd read it a year ago. It's comforting other people have to refer... | | | | | | On a similar note, I used to think while() loops were more efficient than foreach()... | | | | | | I did tests on this about a year ago and got some pretty dramatic results. I'm sure... | | | | | | Thanks for pointing that out, I'll make sure it's fixed. I promise I know the right... | | | | | | I think you meant "comma", not "colon", when you stated:
the correct spelling... | | | | | |
$myNumber = 2;
$myNumberSquared = Math::square($myNumber);
[b] print... | | | | | | Right!
Thank god I don't right articles... | | | | | | Yes, I like the underscore better for file names, because when you copy files... | | | | | | Just my two cents:
I've read somewhere that this:
echo 'Welcome back ',... | | | | | | I knew what he meant, the correction has already been made. Thanks =) | | | | | | I agree with satane and the previous poster; _ is my prefered method. I come from a... | | | | | | Your example, "did i name it myDb or myDB", implies a lack of agreed upon naming... | | | | | | What methods do you use to benchmark your PHP applications? Thanks.
Ben | | | | | | Not true. Passing echo parameters is slower than concatenation. I've done timing... | | | | | | You could do this in at least a few ways...
Use a load generator to check the... | | | | | | [quote]placing variables outside of strings increases readability[/quote]
I think... | | | | | | >>> Post your comment now! | | | | | |
|
 |