phpmd/phpmd — pull request #64 by beberlei (2013-01-13 15:45:03+00:00)
Title: [GH-38] Implement undefined variable rule

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.

In the case of the following example, PHP_PMD will trigger two errors, unused local variable and undefined variable:

function foo()
{
echo $bar;
}

I 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.