2

Possible Duplicate:
Are PHP short tags acceptable to use?

The <?= is one of the very few elegant things about PHP, IMO. Yet, there are people that deliberately avoid it (in favor of the much longer <?php echo). Why would they do that?

Community
  • 1
  • 1
Emanuil Rusev
  • 34,563
  • 55
  • 137
  • 201

5 Answers5

4

<?= is easier to use but some servers don't support short tags. Therefore, if you ever run into a server that doesn't support them, you need to replace all tags.

A more elaborate answer is already given: Are PHP short tags acceptable to use?

Community
  • 1
  • 1
Luwe
  • 3,026
  • 1
  • 20
  • 21
  • Why would anyone setup a server to not support short tags? – Emanuil Rusev Aug 18 '11 at 14:52
  • 1
    They are not supported by 'default'. Why they are not supported is therefore not relevant, that's always a choice of the server admin. – Luwe Aug 18 '11 at 14:54
  • its not a matter of them specifically not supporting it, the default behavior is for them not to be turned on... so the server setup guy needs to specifically support them. – Francis Yaconiello Aug 18 '11 at 14:55
1

Because the feature isn't enabled by default in PHP, so if someone else uses the code who doesn't, the code breaks.

Andreas Eriksson
  • 8,979
  • 8
  • 47
  • 65
0

Because by default servers aren't set up with php short-tag support, its something that needs to be toggled. if for some reason the server does not have short-tag support turned on, your code will error out. better to just add a couple characters, and aviod potential problems.

EDIT

search before posting: Are PHP short tags acceptable to use?

Community
  • 1
  • 1
Francis Yaconiello
  • 10,829
  • 2
  • 35
  • 54
0

The problem is that not all servers support short tags

If you are developing an application for an controlled environment (for example, it will run only on your company server), then I don't see any problems with short tags

But, if it'll be a redistributable code, them you should open all tags explicitly <?php echo ?>

Ortiga
  • 8,455
  • 5
  • 42
  • 71
0

Many servers has got that <? "shortform" turned off.

The only sure way to have your php executed is using the <?php form. so you have to use <?php echo in code you're going to distribute or reuse.

ZJR
  • 9,308
  • 5
  • 31
  • 38