Bug #19708 [Opn]: PHP_CodeSniffer doesn't detect <% and <? if short_open_tag and asp_tags are off
| From: | wiltave at gmail dot com | Date: | Thu, 15 Nov 2012 13:12:11 +0000 |
| Subject: | Bug #19708 [Opn]: 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-9341@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: wiltave@gmail.com
Reported By: wiltave at gmail dot com
-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
Status: Open
Type: Bug
Package: PHP_CodeSniffer
Operating System: Debian Linux (Testing)
Package Version: 1.4.2
PHP Version: 5.4.4
Roadmap Versions:
New Comment:
-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
Previous Comments:
------------------------------------------------------------------------
[2012-11-15 13:10:41] willianveiga
Description:
------------
If short_open_tag and asp_tags are Off in php.ini, using the following
sniff, PHP_CodeSniffer will not complain about coding standards
violations:
<?php
class CIStandard_Sniffs_Php_MustUseFullOpeningTagsSniff implements
PHP_CodeSniffer_Sniff
{
public function register()
{
return [T_OPEN_TAG];
}
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
$content = trim($token['content']);
if ($token['code'] === T_OPEN_TAG && $content != '<?php') {
$error = 'Always use full PHP opening tags (<?php), in case
a server does not have short_open_tag enabled. found %s';
$data = [$content];
$phpcsFile->addError($error, $stackPtr, 'Found', $data);
}
}
}
Test script:
---------------
<?php echo TRUE; ?>
<? echo TRUE; ?>
<% echo FALSE; %>
Expected result:
----------------
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
2 | ERROR | Always use full PHP opening tags (<?php), in case a server
does
| | not have short_open_tag enabled. found <?
3 | ERROR | Always use full PHP opening tags (<?php), in case a server
does
| | not have short_open_tag enabled. found <%
--------------------------------------------------------------------------------
Time: 0 seconds, Memory: 1.50Mb
Actual result:
--------------
Time: 0 seconds, Memory: 1.50Mb
------------------------------------------------------------------------
--
Edit this bug report at https://pear.php.net/bugs/bug.php?id=19708&edit=1