Skip to content

Unused arguments should not be reported for magic methods #132

Open
@jrfnl

Description

@jrfnl

PHP magic methods have a method signature check.

While in most cases it wouldn't make sense not to use the declared/passed parameters, most notably with __call() and __callStatic() there can be situations in which not all parameters are used, like when it is known that the methods which will be called will not take arguments.

class Valid_Magic_Methods
{
    public function __call($name, $args) {
        return $this->$name();
    }
    public static function __callStatic($name, $args) {
        return self::$name();
    }
}

Currently this standard will throw a Unused function parameter $name. (VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable) warning in this situation, but the offending parameter can not be removed as otherwise PHP generates a fatal error.

Refs:

In case you're interested, PHPCSUtils contains some utility methods which could be used to fix this: https://github.com/PHPCSStandards/PHPCSUtils/blob/a9ee9e0afffca398df6f997b44628440aa838d41/PHPCSUtils/Utils/FunctionDeclarations.php#L844-L881

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions