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

[WIP] [GH-38] Implement undefined variable rule #65

Closed
manuelpichler opened this issue Jan 19, 2013 · 6 comments · Fixed by #497
Closed

[WIP] [GH-38] Implement undefined variable rule #65

manuelpichler opened this issue Jan 19, 2013 · 6 comments · Fixed by #497
Labels
Milestone

Comments

@manuelpichler
Copy link
Contributor

manuelpichler commented Jan 19, 2013

There is a class of bugs when you use a variable that is undefined. Some PHP functions allow this when the parameter is passed by reference, however it is still decouraged not define this variables beforehand for clarity.

This rule implements checking for undefined variables. This is done by first collecting all variable assignments, then all parameters of the method/function.\n\nIn the case of the following example, PHP_PMD will trigger two errors, unused local variable and undefined variable:

function foo()
    {
        echo $bar;
    }

therefore propose to work on this patch further by modifying the UnusedLocalVariable to only warn about variable assignments that are not used and keep the undefined variable rule to catch the error class shown above.\n\nPossible Improvements:\n\n* Check if the variable assignment is actually BEFORE the variable usage. Currently it only checks that there is an assignment, it could be after the usage though.

Synced from GitHub: #64

Synced from PivotalTracker: http://www.pivotaltracker.com/story/show/42432495

@ghost
Copy link

ghost commented Jun 5, 2015

👍

@shufenghua
Copy link

also need it

@ravage84 ravage84 modified the milestone: 2.4.0 Nov 7, 2015
@ravage84 ravage84 modified the milestones: 2.4.0, 2.5.0 Mar 8, 2016
@ravage84 ravage84 modified the milestones: 2.5.0, 2.6.0 Jun 28, 2016
@oligriffiths
Copy link

Hey, what's the state of play with this? I notice it keeps getting milestone bumped, seems like a very useful rule.

@ravage84
Copy link
Member

@oligriffiths you are welcome to contribute a PR.

@ravage84
Copy link
Member

ravage84 commented Jun 3, 2017

Moving to Future for now. If we are going to implement this, we can have a look at the proposed changes in https://github.com/phpmd/phpmd/pull/64/files.

@liaol
Copy link

liaol commented Nov 15, 2018

need it

@ravage84 ravage84 modified the milestones: Future, 2.7.0 Jun 25, 2019
@ravage84 ravage84 modified the milestones: 2.7.0, 2.8.0 Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

5 participants