Possible Duplicates:
Are PHP short tags acceptable to use?
What does “<?=” mean when seen in PHP
is there any difference in using <? ?>
to signify a php block, or using <?php ?>
?
if there is not, why would anyone use <?php
?
figure the file extension of .php would give plenty of info about what type of code you are looking at.
The first is called short-open tags and second one is safe open and close tags.
You could enable/disable short open tags in php.ini using short_open_tag
setting.
The short tags should be avoided, have a look at:
PHP Short Open Tag: Convenient Shortcut or Short Changing Security?
Servers must be configured to also use <?
, so it is considered best practice to use <?php
for portability reasons.
From the manual ( http://www.php.net/manual/en/language.basic-syntax.phpmode.php ):
There are four different pairs of opening and closing tags which can be used in PHP. Two of those, and , are always available. The other two are short tags and ASP style tags, and can be turned on and off from the php.ini configuration file. As such, while some people find short tags and ASP style tags convenient, they are less portable, and generally not recommended.
<?php
can always be used. <?
can only be used if the short_open_tag directive is turned on.
short_open_tag tells PHP whether the short form (
<? ?>
) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use<?xml ?>
inline. Otherwise, you can print it with PHP, for example:<?php echo '<?xml version="1.0"?>'; ?>
. Also, if disabled, you must use the long form of the PHP open tag (<?php ?>
).Note: This directive also affects the shorthand
<?=
, which is identical to<? echo
. Use of this shortcut requires short_open_tag to be on.-- Description of core php.ini directives
As others have mentioned, this directive is often turned off so for portability reasons I prefer using <?php ?>
. If this is not an issue, there shouldn't be much difference other than that if the directive is turned on you can also use the <?=
shorthand thingy.
I have never personally run into this issue, but support for <? ?>
is spotty when moving to different servers. I prefer to just stick to <?php ?>
for clarity and consistency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With