How to write PHP Code?

Posted under PHP by wopll on Friday 27 February 2009 at 5:19 pm

1. Canonical PHP tags

The most universally effective PHP tag style is:

<?php ?>

If you use this style, you can be positive that your tags will always be correctly interpreted. Unless you have a very, very strong reason to prefer one of the other styles, use this one.

2. Short-open tags:

Short or short-open tags look like this:

<? ?>

Short tags are, as one might expect, the shortest option.

There are several reasons to resist the temptation of the short-open tag. PHP code written with short-open tags is less portable because you can’t be sure another machine will have enabled them. The most compelling reason now is that this syntax is not compatible with XML—and since XHTML is a type of XML, this implies that none of your code will be able to validate as XHTML.


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Copyright © 2010 blog.wopll.com. WP Theme created by Web Top.