PHP short tags are ok

PHP code blocks are usually started one or two ways. Either by using the full PHP tag: <?php or the short-hand tag, which is just <?. The short-hand tag allows you to do: <?=$var;?> which is the equivalent of <?php echo $var;?>. This is a lot more concise and when you develop as much as I do it's a real time-saver and is more readable.

PHP short tags are enabled by default in PHP although they are officially discouraged because of a potential collision with xml. XML blocks start with <?xml

The other arguments against short-tags is portability. Some web hosts won't have short-tags enabled by default. This is pretty easy to remedy - either by editing the php.ini file or adding a htaccess file.

Now some PHP purists will say that anyone who uses short tags is error prone or antiquated. This is simply unfounded as short tags are not deprecated and as long as you are aware of the shortcomings; won't cause you any more errors..

PHP6 is going to be a major shake up to PHP - a lot of things are going to go like safe-mode / register globals etc. But it would appear that short-tags will be staying. Probably due to the sheer amount of code and rebel coders that rely on them.

Now for super-standards-compliant perfecto projects it may be sensible to use the full PHP tags. But for standard every day use, short tags are ok - so don't let the nay-sayers put you off.



01/05/2009 permalink | Posted in web development | 0 Comments »

Leave a reply

Name
Email (not published)
Website


Bookmark and Share

About me

Adam Jimenez is a freelance web developer who has been professionally developing websites since 2000.

Find me


Projects


Archive


Email updates

Email
Email Marketing by ShiftMail