-1

Someone once told me, that it is good for performance, not to open and close php tags and use echo all the time, like that:

<hgroup>
    <h1><?php echo getHeading1(); ?></h1>
    <h2><?php echo getHeading2(); ?></h2>
</hgroup>

Instead he uses an output variable and echoes it in the end.

$output .= '<hgroup>
    <h1>' . getHeading1(); . '</h1>
    <h2>' . getHeading2(); . '</h2>
</hgroup>';

echo $output;

Does that really make any difference? When do I use which method?

closed as off-topic by gmazzap, s_ha_dum Apr 24 '14 at 13:50

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    This is not WordPress related, so off topic here. However, does not exists any performance difference in the 2 methods, it's a matter of personal preferences. – gmazzap Apr 24 '14 at 13:32
  • As said this is not WP-related. The time that it has to be rendered should still be the same cause the two functions are executed in both scenarios. – bestprogrammerintheworld Apr 24 '14 at 16:28
0

I believe this topic was addressed quite thoroughly here. I might add that within the WordPress community it is common syntax practice to default to echoing tags with an option or alternative/interior function to return the result instead. This I believe is driven by the level of code experience the average user within WordPress has and understanding a simple tag structure is "easier" than string concatenation of a php variable. The goal of extensibiltiy also drives this mentality by providing modular that can be "dropped" into a template in a similar vien of add_action.

Not the answer you're looking for? Browse other questions tagged or ask your own question.