Asked  7 Months ago    Answers:  5   Viewed   43 times

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?

 Answers

45

<? 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.

Wednesday, March 31, 2021
 
Student
answered 7 Months ago
18

You can use the special tags:

<?= get_info(); ?>

Or, of course, you can have your function echo the value:

function get_info() {
    $something = "test";
    echo $something;
}
Wednesday, March 31, 2021
 
fret
answered 7 Months ago
72

Change:

<?php echo ''$_SERVER['PHP_SELF']'.logout=1' ?>

To:

<?php echo $_SERVER['PHP_SELF'], '?logout=1' ?>
Wednesday, March 31, 2021
 
SJain
answered 7 Months ago
56

Option 2 gives you the most flexibility when reusing the code. Next time you use it, you may not want to echo it out directly, but to perform other actions on it, store it for later etc

Saturday, May 29, 2021
 
Silfverstrom
answered 5 Months ago
93

microtime() returns the current Unix timestamp with microseconds. i don't see any math there that does the conversion from microseconds to seconds.

microtime(true) returns the time as a float in seconds

Thursday, August 12, 2021
 
DilbertDave
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :