Why symfony recommends disabling php_short_tags

I am installing the Symfony2 platform for the first time and the web configuration screen says to disable short php tags. Is there a reason for this other than arguments that contradict xml or server incompatibility? Any issues specific to symfony?

+8
php symfony php-shorttags
source share
3 answers

IMHO, feel free to include short_open_tag if you want, and it is safe to ignore this warning issued by Symfony. Heck, I would advocate deleting a check completely.

The two possible problems that you cite are the only theoretical problems that you may encounter when using short open tags, but in practice this has never been a problem for me in 10 years of developing PHP applications.

Even in an XML heavy application, it is unlikely that you have an XML header processed by PHP in more than a few places, and in those few cases the problem is easily circumvented, for example, by echoing from the XML header itself. In this era of post-XHTML, it is even more unlikely that you will develop any web application with an XML header in a PHP template. Controversial argument for a start.

As for the server configuration, even average shared web hosting allows you to change the PHP configuration these days, and this parameter, in particular, can even be set at runtime in a remote feature that you cannot. And who in any case deploys Symfony applications to shared hosting?

Short open tags need some love, and they get some from PHP 5.4, where the echo syntax ( <?= ?> ) Will be enabled regardless of the short_open_tag parameter. Also, while some might argue, short tags are by no means an obsolete PHP function and remain here.

If you use PHP templates and prefer short tag syntax, follow it!

+12
source share

AFAIK, there is nothing specific in Symfony 1 or 2 that will break if you use short tags, but based on personal experience, they are not worth the small amount of input that they save you. You mentioned two valid complaints - XML ​​conflicts and server incompatibilities. This is the reason not to use them. Moving projects from one server to another and replacing short tags is a waste of time :)

+4
source share

In general, it is never recommended to use short_tags mainly because of server incompatibility.

Server incompatibility

Not every PHP server has short_tags . Therefore, if you use short tags anywhere in the project, and sometime in the future, it will be placed on the server with short tags disabled, your site is now broken. You must either go through your code or find / replace or enable short tags on the server, which you may not have the authority to do anyway.

Symfony

Symfony offers several Best Practice recommendations. They are not necessarily things that can do or disrupt development with Symfony, but they are good practice that many professional developers adhere to. Not using short_tags is a good thing for practical use.

In any case, all short labels really save you from having to type a few extra characters from time to time. If you are really worried about entering extra characters, you really should use an IDE or a text editor that supports snippets such as Sublime Text .

+2
source share

All Articles