Suspicious Code Checks

This pass checks for certain, usually suspicious code constructs which might indicate hidden errors in the program:

1. Empty Catch Blocks Without Comment

try {
    $foo->bar();
} catch (\Exception $ex) { }

In this case, it would suggest to add a comment to the catch block.

2. Fall-through in Switches without Comment

switch ($foo) {
    case 'bar':
        if ($x) {
            // ...
            break;
        }
}

Also in this case, it would suggest to add a comment to the case block.

3. Assignment of Null Return Value

This checks whether an expression that always returns null is assigned to a variable, or property:

function foo($foo) {
    echo $foo;
}
$a = foo(); // This assignment would be flagged.

4. Instance-Of with Non-Existent Class

This checks whether the class in an instanceof expression actually exists. These bugs are pretty hard to debug, and do not produce any runtime error.

5. Catch Block with Non-Existent Class

This is the same as check 4), but for classes in the catch block.

6. Overriding Closure Use

This checks if you override a variable that was included from the outer-scope. Typically, that suggests that you should include this variable as a reference:

function foo($a, $b) {
    return function() use ($a, &$b) {
        $a = 'foo'; // would be flagged
        $b = 'bar'; // ok
    }
}

7. Parameter and Closure Use Conflict

This is almost certainly an error in your program:

function foo($a) {
    return function($a) use ($a) { }
}

8. Use Statement Alias Conflict

This checks whether the alias of a use statement conflicts with a class in the current namespaces of the same name. These issues are hard to detect as they only happen if both files are imported, and might go unnoticed for a while:

// Foo/A.php
namespace Foo;

class A { }

// Bar/A.php
namespace Bar;

class A { }

// Bar/B.php
namespace Bar;

use Foo\A; // Conflicts with Bar\A.

class B
{
    public function __construct(A $a) { }
}