[PEAR-BUG] Bug #18670 [Com]: UpperCaseConstantNameSniff fails on dynamic retrieval of class constant

[email protected] ("[email protected]")
Newsgroups php.pear.bugs
Message-ID <[email protected]>
Edit report at http://pear.php.net/bugs/bug.php?id=18670&edit=1

 ID:               18670
 Comment by:       [email protected]
 Reported By:      johnston dot joshua at gmail dot com
 Summary:          UpperCaseConstantNameSniff fails on dynamic retrieval
                    of class constant
 Status:           Open
 Type:             Bug
 Package:          PHP_CodeSniffer
 Operating System: Lunux
 Package Version:  1.3.0
 PHP Version:      5.3.6
 Roadmap Versions: 
 New Comment:

The Patch fixes the problem.

It should be applied to
PHP/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php


Previous Comments:
------------------------------------------------------------------------

[2011-07-18 15:09:30] gennadiylitvinyuk

Added #patch
bug:18670;patch:ConstantsNamingConvention.patch;revision:1310998170;.

------------------------------------------------------------------------

[2011-07-18 15:07:55] gennadiylitvinyuk

I have the same issue.

------------------------------------------------------------------------

[2011-07-15 22:30:53] treegi

Description:
------------
The constant sniff assumes that arguments to constant() should be all
uppercase when it is valid to have constant('self::SOME_CONST'); if you
are doing dynamic constant retrieval

Test script:
---------------
<?php
// bug.php
class ConstTest {
    const TESTER = '1';
    public function __construct() {
        echo constant('self::TESTER');
    }
}
?>


Expected result:
----------------
$ phpcs --standard=PEAR bug.php

--------------------------------------------------------------------------------
FOUND 6 ERROR(S) AFFECTING 3 LINE(S)
--------------------------------------------------------------------------------
 2 | ERROR | Missing file doc comment
 2 | ERROR | Missing class doc comment
 2 | ERROR | Opening brace of a class must be on the line after the
definition
 4 | ERROR | Missing function doc comment
 4 | ERROR | Opening brace should be on a new line
 5 | ERROR | Constants must be uppercase; expected 'SELF::TESTER' but
found
   |       | 'self::TESTER'
--------------------------------------------------------------------------------

Time: 0 seconds, Memory: 5.25Mb

Actual result:
--------------
$ phpcs --standard=PEAR bug.php
--------------------------------------------------------------------------------
FOUND 5 ERROR(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
 2 | ERROR | Missing file doc comment
 2 | ERROR | Missing class doc comment
 2 | ERROR | Opening brace of a class must be on the line after the
definition
 4 | ERROR | Missing function doc comment
 4 | ERROR | Opening brace should be on a new line
--------------------------------------------------------------------------------

------------------------------------------------------------------------


-- 
Edit this bug report at http://pear.php.net/bugs/bug.php?id=18670&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.