Teaches the basics of Proper Indentation in your php source.
Terms of Agreement:
By using this article, you agree to the following terms...
You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
I think it is a basic coding standard to Indent each function, loop, etc. This not only helps others that may be working with your source, But it also helps when you go back and look at your source. Below are some examples of right and wrong.
wrong way:
if($foo==""){$var="1");}
should be:
if($foo=="")
{
$var="1";
}
Steve is right, although it may seem like more coding up front, it'll help you later when you need to read your code. And if you're publishing code that someone else will be reading or using, it becomes even more important that it's formatted in an easy-to-read manner.
Another common convention is to place the opening brace on the same line as the start of the function definition, loop call, etc:
while(1){ echo (If this comment was disrespectful, please report it.)
(having the first bracket on the first line) I find that this is very good. I know that it is neater to have the bracket on a new line, but I really don't like to scrool up and down my code alot. (If this comment was disrespectful, please report it.)
Keep in mind that PHP is an interpreted scripting language. Every time a client requests a document, PHP has to strip out the useless white-space. So, it makes sense to code a program with proper indentation, but all “production releases” should be optimized with some sort of optimizer program. For example, the program could rename all variables to 2 or 3 character variables and delete all useless white-space. (If this comment was disrespectful, please report it.)
Keep in mind that PHP is an interpreted scripting language. Every time a client requests a document, PHP has to strip out the useless white-space. So, it makes sense to code a program with proper indentation, but all "production releases" should be optimized with some sort of optimizer program. For example, the program could rename all variables to 2 or 3 character variables and delete all useless white-space. (If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)