Viewed   91 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

2

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

Friday, November 4, 2022
3

Try this

 <IfModule mod_php5.c>
   php_value short_open_tag 1
 </IfModule>

This would solve the problem

Sunday, December 25, 2022
5

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;
}
Tuesday, August 16, 2022
2

Call one function inside another and it will work:

<meta name="twitter:image" value="<?=
    str_replace(
        "367.jpg",
        "150.jpg",
        substr($imageSrc, 0, strpos($imageSrc, '.jpg')+4)
    )
?>" />

Or do it step-by-step saving to the variable:

# remove tail
$imageSrc = substr($imageSrc, 0, strpos($imageSrc, '.jpg')+4);
# replace size
$imageSrc = str_replace("367.jpg", "150.jpg", $imageSrc)

<meta name="twitter:image" value="<?= $imageSrc ?>" />
Wednesday, October 26, 2022
1

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

Wednesday, November 23, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :