I hope this will pursuade you to stop using short_open_tag syntax.<?= or <?
No Shorthand PHP tags Important: Never use shorthand PHP start tags. Always use full PHP tags.
Always use <?php ?> to delimit PHP code, not the <? ?> shorthand. This is required for PEAR compliance and is also the most portable way to include PHP code on differing operating systems and setups.
short_open_tag
and asp style tags will be DISABLED in php 6.
They are already working to decouple <?= from short_open_tag for php 6
Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.
It's been recommended for several years that you not use the short tag "short cut" and instead to use the full <?php and ?> tag combination. With the wide spread use of 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 we recommend you don't use them.
php.ini values : short_open_tag PHP 4, 5_0 * Default behaviour : on * php.ini-dist : on * php.ini-recommended : on PHP 5_1, 5_2: * Default behaviour : on * php.ini-dist : on * php.ini-recommended : off PHP 5_3: * Default behaviour : on * php.ini-development : off * php.ini-production : off
<?php // output xml header ?> <?xml version="1.0" encoding="utf-8"?>
Well that results in a PHP error: Parse error: syntax error, unexpected T_STRING in ... on line ...
The workaround is pretty simple, just do:
<?php // output xml header echo '<?xml version="1.0" encoding="utf-8"?>';
Also read: https://wiki.php.net/rfc/shortags.
not making use of short tags, means your source code will also be a valid XML document, which allows you to do many things with it such as validation, XSLT translations, etc, as well as allowing your text editor to parse your code for syntax colouring. Every PHP tag will simply be interpreted as an XML processing instruction (commonly referred to as PI). The reason why all the other suggested methods are not advisable is because they contain the characters ?> inside the PHP tag, which the XML parser will interpret as the end of the processing instruction. A processing instruction is defined in XML as: PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' In other words, it explicitly forbids the characters ?> to occur together within a processing instruction, unless they are delimiting the end of the tag. It also requires a PITarget (an identifier starting with a letter) immediately after the initial start delimiter, which means that all short tag formats are also invalid XML. Following these guidelines will result in code that is portable to servers with any configuration and allow you perform many useful tasks on your XML or XHTML source documents. Even if you do not intend to validate or translate your source documents, and you can ignore some incorrect syntax colouring in your text editor, it is still best to get into good habits early.
So I recommend from now on use the full <?php ?> style. Here's one of my old bad coding habits, using a loop with processing in it instead of out of it:
<?php $array=array(); while (sizeof($array)>10) { }
instead of
<?php $array=array(); $count=sizeof($array); while ($count > 10) {}
What I do to break the bad habit is I slap myself on both sides of my face when I notice I did it and immediately correct it after the slap. You may have a different bad-habit fixer, but feel free to use mine, it works really well for me :)