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:
// Example of PHP’s short Codes
$name = ‘Andrew’;
$employer = ‘iwebv2web1.cms.iwebcloud.co.uk’;
Now consider the following HTML snippet:
How are you enjoying life at ?
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:
How are you enjoing life at ?
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:
And compare the readability with this:
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?
Get the latest eCommerce news, reviews and expert advice in your inbox.