<?php vs <? ...Does it matter?
Possible Duplicate:
Are PHP short tags acceptable to use?
<?php
//Some code
?>
or
<?
//Some code
?>
I know the first way is the proper way but PHP code isn't validated. So, besides it saving extra typing & bytes, does it matter?
update Thanks for the replies...
Thanks again
It does, if anyone ever uses your code on a server where short tags are disabled. I work with several servers where they are. Other than that though, no. Using the short version makes your script less portable though for the above mentioned reason. This may or may not be an issue for you.
This is another issue entirely, but related. If you are trying to generate certain types of files from PHP (XML is the candidate that comes up most often for me) then having short tags can be an issue. For instance, the following causes a PHP syntax error:
<?xml version="1.0" ?>
You must instead write the following on a server that has short tags enabled:
<?php echo '<?xml version "1.0" ?>'; ?>
Gah!
If your project is likely to be deployed on different servers (open source software, for example) it is best to always use <?php
However, if you're like me, and always strive for maximum portability, use <?php
even if you don't believe your software will ever leave your server. Most servers have short tags enabled.
However, if they have short tags disabled, and you use them, your PHP will be exposed to the world (if under the document root).
No difference it's just a matter of preference I think, plus why should it matter? it's just another 3 bytes.
Edit:
Forgot to say that you have to enable short hand in php.ini
链接地址: http://www.djcxy.com/p/59432.html上一篇: 有什么区别? 回声
下一篇: <?php vs <? ...有关系吗?