Boo, deleted short tags. Why do people hate short tags again? I can't remember because <? is not valid XML so there shouldn't be any problems with mixing php and xml... hmm... I wonder ....
So when someone uses <?php in their XML document and tries to run it through PHP, will the collective PHP-internals community explode? React? Ignore it?
<%= has been the compatible way forward since 1996 or so, and the community has chosen to ignore it. We've successfully migrated away from HTTP_GET_VARS, register_globals, and other bad habits. But somehow <?php is lorded over others as 'the one true way', as if somehow typing more boilerplate to avoid conflict with 0.02% of the use cases where there's a problem is something to be proud of.
Can we please give up this ``is-valid-XML'' argument already?
Quick counter-example:
<?php echo 'foo ?>' ?>
Guess what:
- if interpreted as XML, the processing instruction ends at the first ?>
- if interpreted as PHP, the PHP code ends at the sencond ?>
...which makes the argument against short tags -- XML validity -- moot. Can't be fixed without breaking backward compatibility either. Let's drop the argument now; otherwise somebody well-meaning will try to apply it and will end up breaking backward-compatibility (and removing a neat feature) yet keeping XML-compatibility broken anyway. Just like Robert Eisele did.
Agreed... I've never used <? in a non-PHP context and it's way easier to type than <?php all the time. Why not just leave it in, or at least change it to something just as short but unique?
Awesome. I remember arguing for it on the mailing lists and I'm extremely happy they did this.
With echo tag you can have a very simple and powerful templating system written in the language itself. (I usually just use two methods, Temaplte::show and Template::get, which both are less than 20 lines long.)
Short tags are why I don't need a template engine for PHP. And can write <?=$name?> instead of <?php echo $name;?>. This had been a unique feature that no other scripting language offers. This is a historic sign indicating that PHP was designed for the web.
It always bugged me that the PHP community didn't pick up on this and run with it. We've had ASP tags since the beginning (almost?) but I think people avoid it out of some anti-MS stance. Rails runs with <%= just fine.
OTOH, you shouldn't ever be generating XML headers from PHP anyway (XHTML is a dead-end, and raw XML should be generated by an XML library), so this shouldn't be that big of an issue.
But, less than question mark and a space are not a valid XML combination. XML processing instructions cannot begin with a space. Likewise, PHP cannot run commands into the short tags, like <?echo $foo; ?>. So, there really is no collision, it's just grandstanding.