Domanda

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?

È stato utile?

Soluzione

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!

Altri suggerimenti

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 :)

In general, it's never a good idea to use short_tags mostly because of server incompatibility.

Server Incompatibility

Not every PHP server has short_tags enabled. So if you use short tags anywhere in a project, and someday in the future it happens to be put on a server with short tags disabled, your site is now broken. You have to either go through your code and find/replace or enable short tags on the server, which you might not have the authority to do anyways.

Symfony

Symfony makes several Best Practice suggestions. They are not necessarily things that will make or break development using Symfony, but they are good practices that many professional developers follow. Not using short_tags is a good thing to put into practice.

Anyways, all short tags really does is save you from having to type a few extra characters every now and then. If you are really that concerned about typing extra characters, you should really be using an IDE or Text Editor that supports snippets, like Sublime Text.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top