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

UnusedParam false positive when param assigned by reference #10916

Open
smaddock opened this issue Apr 19, 2024 · 2 comments
Open

UnusedParam false positive when param assigned by reference #10916

smaddock opened this issue Apr 19, 2024 · 2 comments

Comments

@smaddock
Copy link
Contributor

If a method parameter is used in the method as a reference (AKA alias, i.e., prefixing with an ampersand), Psalm marks that parameter as unused. Removing the ampersand removes the error.

https://psalm.dev/r/b46281057c

(Apologies if this is a duplicate, I searched several times and couldn't find this reported previously.)

Copy link

I found these snippets:

https://psalm.dev/r/b46281057c
<?php

final class MyClass
{
    private \stdClass $config;

    public function __construct(\stdClass $config) {
        $this->config = &$config;
    }
}
Psalm output (using commit 08afc45):

INFO: UnusedClass - 3:13 - Class MyClass is never used

INFO: UnusedParam - 7:43 - Param #1 is never referenced in this method

@jack-worman
Copy link
Contributor

jack-worman commented May 5, 2024

Object are always passed by reference. $this->config = &$config; is the exact same as $this->config = $config;

It saying the param is unused is a bug, but you can avoid it by not having redundant code.
Here is an example of this bug with non-redundant code: https://psalm.dev/r/578763b870

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

No branches or pull requests

3 participants