PHP opening tags question
Possible Duplicate:
Are PHP short tags acceptable to use?
I saw some people use
<?=
instead of
<?php echo
It does make all those
<td something><?php echo $result;?></td>
<td something><?php echo $result2;?></td>
shorter and easy to read (to me at least) but my question is: is it desirable to use this syntax? Or is it deprecated/discouraged/simply wrong?
Thanks!
Supposedly, some people have short tags disabled on their server, so this won't work.
It's best practice to use <?php echo $var; ?>
<?php echo $var; ?>
instead, but some will argue that it's more readable to use short tags and that having them disabled is rare.
For best results, avoid them.
EDIT : Apparently PHP 5.4 will allow you to use <?=
syntax regardless of server configuration (I was not aware). In that case, I still say - avoid it if you care about portability and different environments that may not be running 5.4, or may have short tags disabled.
<? ?>
<? ?>
for PHP blocks is deprecated, but the PHP manual says <?= ?>
is going to stick around (and from PHP 5.4 upwards, it'll be on always, even if short tags are off/removed). So, not deprecated, and common practice.
It can't be deprecated because sometimes ago it was available only with switched on short tags, but will be available always since PHP 5.4
As of me, <?=
is more readable, but you (or your team) should choose your own style
上一篇: “<?”后需要“PHP”吗?
下一篇: PHP开放标签问题