Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive: local scope static variables are mislabled as undefined when accessed #912

Open
6 tasks done
ikari7789 opened this issue Oct 1, 2021 · 0 comments
Open
6 tasks done

Comments

@ikari7789
Copy link

  • PHPMD version: 2.10.2
  • PHP Version: 7.2.34
  • Installation type: composer
  • Operating System / Distribution & Version: macOS 11.6

Current Behavior

The clean code UndefinedVariable rule reports a violation on local scope static variables.

FILE: /path/to/example.php
--------------------------------------------------------------------------------------------------------
 7   | VIOLATION | Avoid using undefined variables such as '$variable' which will lead to PHP notices.

Expected Behavior

Variable should be seen as defined and not report any violations.

Steps To Reproduce:

<?xml version="1.0"?>
<ruleset name="PHP Mess Detector Ruleset"
    xmlns="http://pmd.sf.net/ruleset/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
    xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">

    <rule ref="rulesets/cleancode.xml/UndefinedVariable" />
</ruleset>
<?php

function staticVariableUndefined()
{
    static $variable = 0;

    ++$variable;
}
phpmd example.php ansi example.xml

Checks before submitting

  • Be sure that there isn't already an issue about this. See: Issues list
  • Be sure that there isn't already a pull request about this. See: Pull requests
  • I have added every step to reproduce the bug.
  • If possible I added relevant code examples.
  • This issue is about 1 bug and nothing more.
  • The issue has a descriptive title. For example: "JSON rendering failed on Windows for filenames with space".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant