2

Possible Duplicate:
Are PHP short tags acceptable to use?

<?=$num2?>

$num2 is calling data in an associative array. Is <?= shorthand for <?php echo...? If so what are the limitations and advantages of using this method? I've also noticed you can only use = if you're using the shorthand tags. Why is this?

Community
  • 1
  • 1
Michael Grigsby
  • 11,467
  • 9
  • 33
  • 52
  • 1
    Well, that's just language design, and a coding preference, but also a server setting constraint. Starting from PHP 5.4 the `=` syntax will always work; but as of currently it's often discouraged. – mario Nov 16 '11 at 05:58
  • 1
    @mario I wished they'd taken the lead from Rails and let `=` use HTML encoding by default in 5.4 :( – Phil Nov 16 '11 at 06:02

2 Answers2

2

<?= is short for <? echo. You can only use <?= if you are using shorthand tags as it itself is a shorthand tag. The major disadvantage is it makes your code less portable as many servers don't allow shorthand tags. Some people might consider it less readable or less explicit. If you have full control of the deployment environment and can enable shorthand tags, go ahead and use it if you prefer that style. If you're trying to reduce typing, maybe try a PHP templating engine.

six8
  • 2,886
  • 21
  • 20
2

Yes, <?= is short for <?php echo. They've been threatening to deprecate short tags for some time, but it hasn't happened yet. Still, it's best practice not to use them, mainly because not all hosting services support them. And you don't want to deal with that when moving from one host to another.

ddrace
  • 717
  • 3
  • 12