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

Unused arguments should not be reported for magic methods #132

Open
jrfnl opened this issue Feb 13, 2020 · 4 comments
Open

Unused arguments should not be reported for magic methods #132

jrfnl opened this issue Feb 13, 2020 · 4 comments
Labels

Comments

@jrfnl
Copy link
Collaborator

jrfnl commented Feb 13, 2020

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

@jrfnl
Copy link
Collaborator Author

jrfnl commented Feb 13, 2020

Any fix for this should probably also cover the magic (global) __autoload() function.
Ref: https://www.php.net/manual/en/function.autoload

@sirbrillig
Copy link
Owner

Oh, great point. Thanks!

@sirbrillig sirbrillig added the bug label Feb 13, 2020
@jrfnl
Copy link
Collaborator Author

jrfnl commented Oct 12, 2022

Just noting I recently ran into this again. Utils is getting close to the 1.0.0 release, so maybe we should leave it until that's available ?

@sirbrillig
Copy link
Owner

Oh, thanks. I had forgotten about this issue. I'm stretched pretty thin right now but I'll see if I can write up a quick patch to ignore unused params in these magic methods, but if not we'll just wait for the Utils functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants