Using PHP Short Tags

PHP Short Tags refers to '<?' when a full tag is '<?php'. Most PHP installations has short tags support - but there are a few installations that have turned it off. So it is recommended that you don't use the short tags in your app if you plan to distribute it.

Short tags are considered bad because they are in conflict with XML's open tag - '<?xml'. If it is a PHP file, the interpreter will think everything after the '<?' is PHP code. As a result it will show a parsing error.

This problem can be solved easily - I use this code...

<?php echo '<?'; ?>xml

I use the full tag almost all the time. The only exception is that I use <?= $print_me ?>. And I am not prepared to give that up.

I follow the MVC pattern in my projects. My PHP framework, iFrame, is an MVC framework. In the template(view) part, there is a lot of usage of such tags. It is more concise and more readable than the alternative...

<?= $print_me ?>
<?php print $print_me; ?>

You tell me - which is better?

I hear that they will be introducing <php= > in PHP 6. Until then, I will continue to use <?= ?>.

blog comments powered by Disqus
Subscribe to Feed