Skip to content

Wrong keyword detection (v3.7.0) #3612

@8kb

Description

@8kb

Describe the bug
phpcs parse const name as keyword, and expect its lowercase. But its legal const name not restricted by php or by standard.
Yep, in other context its keyword, but its allowed to use it as const name.

If in some reason you decide what its not allowed -> it will show relevant error, not about "lowercase'.

Code sample

namespace Brand\Ast;

class Node
{
    public const AND = '&&';
    public const NOT = '!';
    public const EMPTY = 'empty';
}

To reproduce
Steps to reproduce the behavior:

  1. Create a file called Node.php with the code sample above...
  2. Run phpcs --standart=PSR12 Node.php
  3. See error message displayed
------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------
 9 | ERROR | [x] PHP keywords must be lowercase; expected "empty" but found "EMPTY"
------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------

Expected behavior
No error, or (if its restricted by standard) warning about reserved word

Versions:

  • OS: Linux
  • PHP: 7.1
  • PHPCS: 3.7.0
  • Standard: PSR12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions