问题
Possible Duplicate:
Are PHP short tags acceptable to use?
I'm just learning php and (been learning for about 6 months) and in a tutorial that I'm going through, it's using php shorthands, so when I looked it up on google, I came to this stack overflow question StackOverflow question where one of the popular answers says that shorthands are bad.
I know one of the following comments then suggest that it's not bad but I also remotely remember reading from a php book before that it's not always good to use them. So I'm a bit confused, are they bad or not?
回答1:
It is generally a bad idea because of portability. All PHP configurations understand the <?php ?>
tags, but not all are configured to use <? ?>
.
Same thing goes for <? =$variable; ?>
for printing.
回答2:
They are not bad actually, but you can say that it's kinda a bit lazy sort of thing to do for a GOOD TECHNICAL programmer. Why I'm using this word "GOOD TECHNICAL" is because, since they know about the technicalities of PHP, then they should also know whether the shorthands will be of any use or not in the long run, whenever any adjustments is to be made regarding the fine tunings of the PHP Server.
But still, it's one of my views & may be it will not match with others' answers.
回答3:
I personally never use them because I find it makes my code ugly, hard to read and harder to debug. I'm talking about shorthands like the one-line if statement. Not every PHP configuration understands short open and ending tags, and not every programmer knows about shorthand notation so this might be a problem if you want to share code at some point. I wouldn't advise using it.
回答4:
the code "<? ?>
" depends on the "php.ini", you should change the state short open tag. While the code "<?php ?>
" can run everytime everywhere, without any configuration.
I recommend you to use smarty template.It's perfectly easy to use. And code is beautiful.
来源:https://stackoverflow.com/questions/5208015/is-using-php-shorthands-bad