HTML5 Canvas
Written by: Simon Sarris
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Web Driver
  3. MVVM
  4. REST
  5. ADO.NET
  1. HTML5
  2. Ajax
  3. jQuery Selectors
  4. CSS Part 1
  5. Git

Link Details

Link 335427 thumbnail
User 364926 avatar

By heavyworks
via heavyworks.net
Published: Jan 04 2010 / 04:30

While it’s not a great secret, many people still not aware of the alternative syntax for control structures under PHP. The C-like syntax for control structures are very intuitive but can deal lots of trouble when your code has lot of pages and lots of ifs, fors, while and therefore lots of opening and closing braces. This article discuss the use of this alternative syntax that is great for improving your code readability.
  • 9
  • 2
  • 4022
  • 0

Comments

Add your comment
User 244651 avatar

jakyra replied ago:

1 votes Vote down Vote up Reply

If you've got deeply nested if statements where {} are a problem maybe you should consider refactoring your code...

User 364926 avatar

heavyworks replied ago:

0 votes Vote down Vote up Reply

Sure jakyra, I strongly agree with you. No function should have more than a page of code... or half!

User 233461 avatar

antych replied ago:

0 votes Vote down Vote up Reply

This syntax is very useful (and usually recommended) for php mixed with html in templates, view scripts etc.
Your examples are pretty useless, they don't show any advantages of using it.

User 364926 avatar

heavyworks replied ago:

0 votes Vote down Vote up Reply

Antych, the examples are just illustrating the syntax, the explanation of the advantages were kept in the text only. Do you have a good case that we can use to exemplify the advantage?

User 233461 avatar

antych replied ago:

1 votes Vote down Vote up Reply

A good use case could be a php code embedded in html for printing tables rows. In that case it's much easier to spot where the statement ends if you have > instead of >. This is especially useful if combined with other statements.
Normally this is not an issue because plain php code can be kept small and properly indented, but this is not the case when dealing with content (html). html is the key here, this is where this syntax becomes useful.
You can find some examples in ZF documentation, like top of this page http://framework.zend.com/manual/en/zend.view.scripts.html

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (9)



Voters Against This Link (2)