views:

3395

answers:

3

Are they equal in safeness? I was informed that using

<?=$function_here?>

was less safe, and that it slows down page load. So I am now strictly biased to using echo.

I just wanted to know the advantages/disadvantages, or are they pretty much the same.

+9  A: 

<? and <?= are called short open tags, and are not always enabled (see the short_open_tag directive).

Actually, in the php.ini-production file provided with PHP 5.3.0, they are disabled by default :

$ grep 'short_open' php.ini-production
; short_open_tag
short_open_tag = Off

So, using them in an application you want to distribute might not be a good idea : your application will not work if they are not enabled.

<?php, on the other side, cannot be disabled -- so, it's safest to use this one, even if longer to write.


Except the fact that short open tagas are not necessarily enabled, I don't think there is much of a difference.

Pascal MARTIN
+19  A: 

Echo is generally just better to use because...

  1. It supports good programming style.
  2. It can't be turned off in php.ini (short tags can be)
  3. Short tags will be removed in PHP 6)

But, they are generally the same. See also:

  1. http://stackoverflow.com/questions/200640/are-php-short-tags-acceptable-to-use
  2. http://stackoverflow.com/questions/234241/how-are-echo-and-print-different-in-php
carl
what?! 6 is removing them? lame-sauce! if i'm in charge of the server i don't care about portability. `<?=` is so much nicer than `<?php echo`
Mark
@Mark - it's more standardized for all to use <?php ?>, instead of one programmer using <% %>, the other using <%= %>, and another one <? ?> and they don't know they all speak the same language.
thephpdeveloper
Worse of all: <script language="php"> ... </script>
thephpdeveloper
The php community's aversion to short tags just baffles me; removing them altogether n php6 is just final proof to me that the php design team are nuts. <?= $foo ?> is so much cleaner in a template than <?php echo $foo; ?>
DGM
php6 reason is just not true
Col. Shrapnel
yeah apparently php6 will lose the asp notation: "<%". Not all short-tags. So "<?" is still valid and reason "3" above is false.
keyle
PHP6 or whatever the next version will be called will *NOT* remove short-open-tags. If anything they will be disabled by default.
Gordon
+2  A: 

So why don't they just remove the option to turn off short open tag and let it be enabled by default.

This is a VERY dangerous move by PHP. The reason being, if you put your existing code that has short tags in it on a PHP6 server and someone views that page, they will get the raw code downloaded to their browser which you can view. This could seriously kill off PHP.

Ritey
So you're saying nothing should ever be deprecated? PHP has been warning against short tags for a couple years now. If they are deprecated, developers that have ignored the warning will be hoist on their own petard.
dnagirl
No I am not saying that nothing should be deprecated. But think about the implications in real life, not in a programmers dream world.How many php pages are out there that contain config files with passwords etc inside that will all of a sudden be exposed to all who view.Yes,that is poor programming, but allowing this will harm more than the credability of the programmer, it could potentially lead to a complete mistrust of PHP by the public as a whole.And ALL of that could be avoided by, continuing to allow short tags OR not lettin the contents of the shorttag go through to the user.
Ritey
Be in on your own heads....!
Ritey
Are you sure that's what would happen?
pbreitenbach