Dave
Dave

Reputation: 29121

<?php echo vs <?= is one "echo" better than the other? (in normal PHP and in CakePHP)

In a lot of CakePHP examples, I see <?php echo $myVar; ?> I've always written this in shorthand like <?php=$myVar?>

Is there any difference? Is <?php echo better for some reason? I always lean toward the shorter, but - when I see everyone else using the <?php echo, I wonder - maybe I'm doing it wrong.

What about in CakePHP - is it different for some reason?

Upvotes: 0

Views: 134

Answers (1)

Matt Huggins
Matt Huggins

Reputation: 83279

<?= or <?php= has to be enabled for it to work properly via the short_open_tag in your php.ini. Since some systems out there have this value disabled, it's encouraged that you use <?php echo to ensure that your code will always work on any system it runs on.

Upvotes: 8

Related Questions