Last modified: 2014-11-19 21:50:21 UTC
It would be helpful to comment or downvote if there was whitespace (or possibly any character) before the <?php/<? tag. This causes unexpected output, which can lead to annoying issues. It could initially be done as a non-voting job. PHP CodeSniffer might be one way to implement this check.
Maybe something as lame as: grep --perl-regexp '\s+\<\?php' -R mediawiki/core But that in turns return a toooon of false positive since we have templates using <?php :-D
(In reply to comment #1) > But that in turns return a toooon of false positive since we have templates > using <?php :-D Yeah, I was going to say, you'd want to check the first line only or we'd probably get a lot of false positives.
Yeah, I meant the first line, just forgot to say it. I found a good way to do it. The relevant CodeSniffer rule is Generic.PHP.CharacterBeforePHPOpeningTag. I tested it with: phpcs --standard=Generic --sniffs=Generic.PHP.CharacterBeforePHPOpeningTag somefile.php
Ah thanks for looking in codesniffer rules! The Generic.PHP.CharacterBeforePHPOpeningTag rule looks almost like something we could use. Unfortunately it complains whenever the T_OPEN_TAG token is not the very first token, for example when we have several open tags in a file. A few examples from core: includes/Feed.php includes/SkinTemplate.php includes/api/ApiFormatBase.php includes/templates/Userlogin.php Not ideal yet :(
You're right. The error message is not consistent with the actual behavior.
The CharacterBeforePHPOpeningTag sniff is good, but we can't use it as-is because it also warns when you use multiple <?php tag in the file (e.g. Skin templates). We should create our own version based on CharacterBeforePHPOpeningTag that only warns for the first one.
https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Generic/Sniffs/PHP/CharacterBeforePHPOpeningTagSniff.php
Krinkle: Over a year since last activity, removing Krinkle as assignee. He know how to re-add if he wants :)