Bug #19708 [Fbk->Csd]: PHP_CodeSniffer doesn't detect <% and <? if short_open_tag and asp_tags are off
| From: | gsherwood at squiz dot net | Date: | Tue, 20 Nov 2012 01:14:44 +0000 |
| Subject: | Bug #19708 [Fbk->Csd]: PHP_CodeSniffer doesn't detect <% and <? if short_open_tag and asp_tags are off | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-9360@lists.php.net to get a copy of this message | ||
Edit report at https://pear.php.net/bugs/bug.php?id=19708&edit=1
ID: 19708
Updated by: gsherwood@squiz.net
Reported By: wiltave at gmail dot com
Summary: PHP_CodeSniffer doesn't detect <% and <? if
short_open_tag and asp_tags are off
-Status: Feedback
+Status: Closed
Type: Bug
Package: PHP_CodeSniffer
Operating System: Debian Linux (Testing)
Package Version: 1.4.2
PHP Version: 5.4.4
Assigned To: squiz
Roadmap Versions:
New Comment:
-Status: Feedback
+Status: Closed
Previous Comments:
------------------------------------------------------------------------
[2012-11-20 00:23:13] willianveiga
I understand. Maybe you can close this bug report.
Thank you again.
------------------------------------------------------------------------
[2012-11-18 23:22:01] squiz
I guess the problem is really that when those settings are off, the file
is not valid
PHP. I don't tokenize PHP files character by character (like I do for
CSS and JS) so I
dont know what context those tags are in.
This could easily be done by a sniff though. One that detects if you are
using short
open tags and then bans them. It could look for T_OPEN TAG for cases
where the ini
setting is ON and it could also look for T_INLINE_HTML and look inside
that content
for cases where the ini setting is OFF.
Adding additional tokenizing to the core for this would slow down
processing, so a
sniff works out better because it is optional to include in a standard.
------------------------------------------------------------------------
[2012-11-16 18:00:30] willianveiga
Greg Sherwood, I got your point, but I think PHP_CodeSniffer should
detect both as T_OPEN_TAG even if these configuration are set off.
I've noticed about behaviour but somebody could not do the same. Using
just my sniff above, without your recomendation, somebody with
short_open_tag and asp_tags Off would not have the same code violations
as somebody with these directive On. It would create inconsistencies.
Maybe we should report it to PHP developers.
But anyway, I am not sure at all if it makes sense. What do you think
Greg?
Thank you very much and sorry about my english.
------------------------------------------------------------------------
[2012-11-15 20:37:27] squiz
-Status: Open
+Status: Feedback
-Assigned To:
+Assigned To: squiz
This is expected behaviour because PHP will not tokenize those tags as
open and
close tags. It tokenizes them as T_INLINE_HTML.
If you run PHPCS over a file that only contains short open tags with
that ini setting
disabled, you'll get this:
FILE: /Users/gsherwood/Sites/Projects/PHP_CodeSniffer/temp.php
--------------------------------------------------------------------------------
FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
1 | WARNING | No PHP code was found in this file and short open tags
are not
| | allowed by this install of PHP. This file may be using
short
| | open tags but PHP does not allow them.
--------------------------------------------------------------------------------
If you want to write a sniff that detects short open tags, you're going
to need to look
for T_INLINE_HTML tokens and then see if you can find <? or <% tags in
the content.
They will look like this:
Process token 0 on line 1 [lvl:0;]: T_INLINE_HTML => <? echo TRUE; ?>\n
Process token 1 on line 2 [lvl:0;]: T_INLINE_HTML => <% echo FALSE;
%>\n
So should be fairly easy to find.
If that doesn't make sense, please let me know and I'll try and help get
your sniff
working.
------------------------------------------------------------------------
[2012-11-15 13:12:11] willianveiga
-Summary: PHP_CodeSniffer doesn't detect <% %> and <?
?> when
short_open_tag and asp_tags
+Summary: PHP_CodeSniffer doesn't detect <% and <? if
short_open_tag and asp_tags are off
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://pear.php.net/bugs/bug.php?id=19708
--
Edit this bug report at https://pear.php.net/bugs/bug.php?id=19708&edit=1