5

Possible Duplicate:
Are PHP short tags acceptable to use?

Which is better to use, or considered better practice: <?php or <?. I've always wanted to know. Or is it more of a preference for the programmer.

Community
  • 1
  • 1
brenjt
  • 15,997
  • 13
  • 77
  • 118

4 Answers4

11

<?php is the official standard. I've never encountered a problem where a browser was confused, but just using <? can also declare XML and might not be the best habit to form.

I'll tell you this though - other programmers will always appreciate the standard. I would go with <?php for sure.

animuson
  • 53,861
  • 28
  • 137
  • 147
Kai Qing
  • 18,793
  • 5
  • 39
  • 57
  • 2
    Note that the short echo tag `=` is always available as of PHP 5.4, regardless of configuration settings, so it could be considered official. This is probably likely due to the popularity of MVC frameworks where extensive use of PHP/HTML templates is used. However, I do agree with you regarding always staying away from `` to open PHP blocks. – Matthew Nov 04 '11 at 03:38
  • yeah, anymore = is preference the same way = $somevar?> is the same as = $somevar; ?> but coworkers or anyone that adopts the code after you might not be pleased to find this in your code since it was a big hoo-ha once upon a time that = was deprecated or planned to be or something. I have to go long form all the time cause I'm in the client based world, so future arguments can be avoided if I just follow the book, so to say. – Kai Qing Nov 04 '11 at 03:47
3

<?php - always, definitely.

Several reasons; the biggest being "disambiguates PHP from SGML (e.g. XML)".

animuson
  • 53,861
  • 28
  • 137
  • 147
paulsm4
  • 114,292
  • 17
  • 138
  • 190
3

As of PHP 5.4, <?= will be available regardless of the short_open_tags ini parameter, so if you're forward-looking you could get away with using <?= inside HTML, in place of <?php echo, however for non-echos always use <?php as <? still depends on the ini.

That said, many hosts have only recently adopted 5.3, and 5.4 is only in beta so if this is a library or something that might reach other's servers soon, I'd stick with <?php for both.

connec
  • 7,231
  • 3
  • 23
  • 26
0

I may recommend <?= ;?> in HTML code. But, I will alawys recommend <?php whenever because it's standard and less confusion with XML by example.

animuson
  • 53,861
  • 28
  • 137
  • 147
David Bélanger
  • 7,400
  • 4
  • 37
  • 55