Skip to content

Suppress function.unusedParameter for params starting with _ #15480

Closed
phpstan/phpstan-src
#6743

Description

@bpfoley

Feature request

Sometimes it's desirable to have free standing functions with one or more unused parameters. This can happen, for example, if you're implementing something like a router that dispatches to a registered function based on some runtime parameter.

function hello_handler(string $method, array $params, array $data): string
{
    return "Hello, world!";
}

Suppressing the warnings for this function can be done by explicitly referencing them in PHPDocs, but this can be verbose:

/**
 *  @param string $method
 *  @param array<string, string> $params
 *  @param array<string, string> $data
 */
function hello_handler(string $method, array $params, array $data): string
{
    return "Hello, world!";
}

Other language ecosystems allow this to be avoided in a couple of ways:

  • Go treats arguments named _ as dummy arguments.
  • Rust uses the same rule for unused variables and function params.
  • Python's ruff uses _prefix for to inhibit the unused-function-argument warning

Even in PHPStan, the _prefix rule is used in UnusedVariableRule.php for assign.unused and the like.

Adding this for function.unused and co. is very simple.

Did PHPStan help you today? Did it make you happy in any way?

Yes! I'm delighted to see all the new unused warnings in PHPStan 2.3 and they're helping me to clean up a legacy codebase.

Activity

  1. added a commit that references this issue on Oct 14, 2026
    c7e97af
  2. claudepache commented on Oct 15, 2026

    @claudepache

    You could implement such a rule for your project with a custom Ignore Error Extension.

  3. bpfoley commented on Oct 15, 2026

    @bpfoley
    Author

    3. You could implement such a rule for your project with a custom Ignore Error Extension.

    Oh nice! Thanks for the suggestion. I'll probably do that for now, but I think this might be a useful feature to have in PHPStan.

  4. bpfoley commented on Oct 16, 2026

    @bpfoley
    Author

    Of course, you can avoid an extension altogether by simply adding the following to your phpstan.neon

    parameters:
        ignoreErrors:
            # Ignore unused function params prefixed with `_`
            - message: '#(Function|Method) .* has an unused parameter \$_.*\.#'
            - message: '#(Function|Method) .* has a parameter \$_.* that only flows into values that are never used\.#'
    
  5. staabm commented on Oct 17, 2026

    @staabm
    Contributor

    needs a phpstan.org/try reproducer

  6. bpfoley commented on Oct 17, 2026

    @bpfoley
    Author
  7. reopened this on Oct 18, 2026
  8. added 4 commits that reference this issue on Oct 18, 2026
    2a84448
    aa57bb7
    a4e576f
    f252df7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions