News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sameer Borate's Blog:
The benefits of colon syntax for control structures
January 15, 2009 @ 08:48:33

In this recent post to his CodeDiesel.com blog, Sameer is promoting the use of colons in control structures over curly braces.

PHP offers a alternative syntax for some of its control structures- if, while, for, foreach, and switch, where you change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively. [...] With the colon syntax you just have to match a '˜if' with a '˜endif' or a '˜for' with a '˜endfor'. When you are mixing HTML with PHP in web pages the code can become quite dense and confusing if it uses a lot of braces.

An example is included showing its use in "if" and "white" statements. With most editors and IDEs supporting brace matching and code folding, this is less of an issue, but it can help make for cleaner code.

1 comment voice your opinion now!
control structure colon curly brace alternative syntax advantage


blog comments powered by Disqus

Similar Posts

Bjarte Karlsen's Blog: My vim setup for editing php files

Cocoliso's Blog: Adding A Syntax Highlighter To Your Site: The Power Of Geshi

SitePoint PHP Blog: Why Choose PHP Over Alternatives?

Ask About PHP: PHP's alternative syntax and why it’s useful

Gonzalo Ayuso's Blog: Keep our PostgreSQL databases synchronized with PHP. Database version control


Community Events





Don't see your event here?
Let us know!


language experience release framework testing threedevsandamaybe code unittest series laravel list opinion introduction podcast community install developer wordpress interview refactor

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework