Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Symfony recommend turning php_short_tags off

I'm installing Symfony2 framework for the first time and the web config screen says to turn php short tags off. Is there any reason for this besides the arguments that in conflicts with xml or server incompatibility? Any issues specific to Symfony?

like image 983
dardub Avatar asked Oct 25 '11 19:10

dardub


2 Answers

IMHO, feel free to enable short_open_tag if you prefer, and it is safe to ignore this warning issued by Symfony. Heck, I'd advocate removing the check entirely.

The two possible problems you cite are the only theoretical problems you might encounter from using short open tags, but in practice this never has been an issue to me in my 10 years developing PHP applications.

Even in XML-heavy application, it is unlikely you have an XML header parsed by PHP in more than a very few locations, and in those few occasions the problem is easily circumvented, by for example echoing the XML header itself. In this post-XHTML era, it is even more unlikely you'll be developing any web application with an XML header in a PHP template. A moot argument to begin with.

As far as the server configuration goes, even the average shared webhosting allows the PHP configuration to be modified these days, and this setting in particular can even be set at runtime in the remote possibility you can't. And who's deploying Symfony applications to a shared hosting anyway?

Short open tags need some loving, and they are getting some in PHP 5.4, where the echo syntax (<?= ?>) will be enabled regardless of the short_open_tag setting. Also, despite of what some might claim, short tags are in no way a deprecated PHP feature, and is here to stay.

If you use PHP templates, and prefer the short tags syntax, go for it!

like image 170
Gerry Avatar answered Nov 15 '22 20:11

Gerry


AFAIK, there's nothing specific in Symfony 1 or 2 that will break if you use short tags, but speaking from personal experience, they're not worth the small amount of typing they save you. You mention two valid complaints - XML conflicts and server incompatibility. Those are reason enough not to use them. Moving projects from one server to another and having to replace short tags is an annoying waste of time :)

like image 23
Steven Mercatante Avatar answered Nov 15 '22 19:11

Steven Mercatante