HomeCoding & Programming

PHP short_open_tag = On should not be used

PHP short_open_tag = On should not be used
Like Tweet Pin it Share Share Email

After a fresh installation you could find that PHP short_open_tag disabled by default in php.ini file.

 

You can check by using phpinfo() PHP function.

Under PHP Core setting you can find as below

 

Directive Local Value Master Value
short_open_tag Off Off

 

If “short_open_tag” is found off in your php.ini file then you cannot use short form (<? ?>) of PHP’s open tag and you must use long form of PHP tags (<?php ?>) instead, otherwise any PHP code inside these tags will not be parsed as PHP.

 

Drawback of PHP short_open_tag if you have enabled.

 

1) Setting this value to off allows for easier use alongside XML by providing the ability to use <?xml ?> inline without having to print it with PHP echo ‘<?xml version=”1.0″?>’; ?>.

 

With the wide spread use of XML(SOAP, XMLRPC, REST-XML) and use of these tags by other languages, the server can become easily confused and end up parsing the wrong code in the wrong context. But because this short cut has been a feature for such a long time, it’s currently still supported for backwards compatibility, but it’s recommend you don’t use them.

 

2) All the standard library use <?php ?>, full php tags so we can say it’s a standard, if you are open source script (distributable or portable script) writer or have PHP open sources community member then it’s always recommended to use full tag instead of short_tag as by default PHP have it disabled in php.ini settings.

 

3) Due to security reasons in some extent it’s advised to not to use short_open_tag.

 

If you still want to use short_open_tag or if you have just entered in a large application that is previously build by any other developer and he have used short_tags in many places, but your you php setting is was disabled then you should enabled short_open_tag, let me tell how you should do this quickly.

 

1) Open you root’s .htaccess file and add the following in that

php_flag short_open_tag on

or

php_value short_open_tag 1

 

2) If you php.ini access and can update any php directive and setting then open php.ini file and change
short_open_tag = Off to short_open_tag = On

It’s always advised to start Apache services after any changes in php.ini settings.

 

3)

 ini_set( "short_open_tag", 1 ); 

will not work, if you are trying to do as it (short_open_tag) is marked as PHP_INI_PERDIR in PHP < 5.3.0, which means you can’t change it with ini_set(). You can check this by below link.

 

Description of core php.ini directives