Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP echo vs PHP short echo tags

Are they equal in safeness? I was informed that using

<?=$function_here?> 

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

What are the advantages/disadvantages?

like image 944
homework Avatar asked Sep 06 '09 20:09

homework


People also ask

Should I use PHP short tags?

Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.

What is short open tag in PHP?

The <= tag is called short open tag in PHP. To use the short tags, one must have to enable it from settings in the PHP. ini file.

What is echo tag in PHP?

The echo() function outputs one or more strings. Note: The echo() function is not actually a function, so you are not required to use parentheses with it. However, if you want to pass more than one parameter to echo(), using parentheses will generate a parse error.

What is the difference between PHP echo and PHP return?

Echo is for display, while return is used to store a value, which may or may not be used for display or other use.


1 Answers

<? and <?= are called short open tags, and are not always enabled (see the short_open_tag directive) with PHP 5.3 or below (but since PHP 5.4.0, <?= is always available).

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 it is longer to write.


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

like image 61
Pascal MARTIN Avatar answered Sep 23 '22 02:09

Pascal MARTIN