[TYPO3-core] CGL proposal: Dropping the closing PHP tag

Andy Grunwald [wmdb] andreas.grunwald at wmdb.de
Mon Oct 22 14:46:14 CEST 2012

To this topic there are many discussions.
Most frameworks (and the PHP docs as well) recommend to delete the 
closing PHP ("?>")-tag.

But in reality, this is only a excuse to create valid and strict PHP code.

The following desciption are copied from [1] (Stefano Kowalke and 
Philipp Gampe)
Some background:
The tags <? and ?> are XML Processing Instructions (PI). The php inside 
the tag (<?php ) is called a PITarget. So after the XML syntax rules 
these PIs MUST be closed. If you don't close it, your document will not 
XML valid.


I assume that even php.net recommend this "removing-the-php-closing-tag" 
attitude is just a workaround for lazy developers and those who are not 
able or not willing to use a modern IDE and/or not able to configuring 
the editor to remove a newline at EOF.
On top of that, PHP even does allow a newline feed directly after the 
closing tag, thus ... 3f 3e 0a is equivalent to ... 3f 3e. Only a real 
newline (... 3f 3e 0a 0a) is bad, but all IDEs support removing empty 
lines at the end of the file.

IMHO one should not support a too lax way for developers that just do 
not want to code "strict". But (IMHO) PHP is not strict enough anyway if 
it stumbles over a nonsense statements. And two opening <?php tags are 
just invalid code (in terms of logic).

At the end:
I`m a developer and developers are lazy. So on one side i`m +1 for 
remove the closing php tag.
On the other side I`m a developer and developers want to get perfect 
results. After the explenation from Stefano (see above) you know that 
open and closing this processing instructions is valid code and to open 
a PI and DON`T close it is _invalid_.

Result: +/-0


PS: I`m only the guy who adapt the CodeSniffer rules :D

[1] https://github.com/squizlabs/PHP_CodeSniffer/pull/49

More information about the TYPO3-team-core mailing list