开发者

PHP opening tags question [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Are PHP short tags acceptable to use?

I saw some people use

<?=

instead of

<?php echo

It does make all those

&开发者_开发技巧lt;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; ?> 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


<?= is known as short tags, PHP framework like CI support this and you can even add support for these in your php.ini files. That said, you should not use this tag at all. This is not so commonly encouraged and now a standard PHP tag with 5.4, using non standard tgas reduces the portability of your scripts. Time to correct my self, this is standard tag, I was stuck with 5.3 :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜