PHP Short tags: Are they good or bad?

Recently in the office chatroom we had a discussion regarding PHP’s short tags:

 

For those that don’t know what PHP Short Tags are, they are basically a shorthand for PHP’s echo or print statements:

[pyg language=”php”]
// Example of PHP’s short Codes
$name = ‘Andrew’;
$employer = ‘iwebv2web1.cms.iwebcloud.co.uk’;
?>
[/pyg]

Now consider the following HTML snippet:

[pyg language=”html”]

Welcome

How are you enjoying life at ?
[/pyg]

Pretty clear and concise huh? This is straightforward and easy to use, but what if you have many of these statements to output on a page? This is what PHP Short Tags were created for. Using syntax similar to short tags found in Microsoft Active Server Pages (ASP) or Java Server Pages (JSP) you can do the same with less typing:

[pyg language=”html”]

Welcome

How are you enjoing life at ?
[/pyg]

Personally I don’t like using PHP Short Tags. Firstly, they can actually be disabled in PHP’s config file, php.ini which means you can’t guarantee code portability. Secondly I think it makes some code unreadable. Consider the following:

[pyg language=”html”]

[/pyg]

And compare the readability with this:

[pyg language=”html”]

[/pyg]

I personally think the second example is much easier to read. As Aaron pointed out there are valid reasons to use PHP Short Tags. New developers coming from ASP or JSP would understand them easier and they are marginally faster to parse.

What do you think? Are PHP Short Tags a good or bad thing?


Share this article

Posted in Development

Tagged

Call us on 01785 279920

Our friendly Magento experts are happy to answer your questions.

Contact us now

Email alerts

Get the latest eCommerce news, reviews and expert advice in your inbox.