Miscellaneous Usage Context Checks

This pass performs a couple of context sensitive usage checks.

1. Method Calls on Non-Objects

class A
{
    private $b;

    public function __construct(B $b = null)
    {
        $this->b = $b;
    }

    public function foo()
    {
        $this->b->bar(); // possible method call on null
    }
}

2. Foreach Expression, and Value Variable

Checks that the expression is traversable, and if the variable is passed as reference, it also ensures that the expression can be used as a reference.

foreach ($expression as &$variable) { }

3. Missing Argument on Function/Method Calls

Checks whether a function, or method call misses a required argument.

function foo($a) { }
foo(); // missing argument

4. Argument Type Check

Checks whether an argument type can be passed to a function/method. Currently, two different levels are supported:

  1. Strict: The passed type must be a sub-type of the expected type.
  2. Lenient (default): In lenient mode, we make a few exceptions to the strict sub-type requirement. For example, we treat string, integer, and double types as interchangable. So, if a string is expected, an integer, or a double would also be acceptable.
Tip: If you have an existing code-base, lenient mode is most likely what you want. If you start a new project, using strict type checking is recommended.