Skip to content

array&callable is not reported as a wrong param #14549

Closed
phpstan/phpstan-src
#5565

Description

@VincentLanglet

Bug report

callable&array offsets and iterable value are understood as object|non-falsy-string but the value is not reported when passed as a param to another method. Even if the array is still understood as array<mixed> it should have been reported on level 9-10 (but best would be on lower level).

https://phpstan.org/r/d6ef05eb-6a35-4621-a996-d6558786e70f

NB: It currently works fine for a constant array
https://phpstan.org/r/a02622d4-7cbf-4c92-b80a-e60cd0afe094

Code snippet that reproduces the problem

https://phpstan.org/r/d6ef05eb-6a35-4621-a996-d6558786e70f

Expected output

And the $this->call($task); call should report an error since array<int> does not accept the type.

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

No response

Activity

  1. added this to the Easy fixes milestone on Apr 28, 2026
  2. ondrejmirtes commented on Apr 29, 2026

    @ondrejmirtes
    Member

    We could just fix MissingTypehintCheck.

  3. changed the title [-]array&callable is not narrowed enough[/-] [+]array&callable is not reported as a wrong param[/+] on Apr 30, 2026
  4. phpstan-bot commented on Apr 30, 2026

    @phpstan-bot
    Contributor

    @VincentLanglet After the latest push in 2.2.x, PHPStan now reports different result with your code snippet:

    @@ @@
      8: Method MondayMorning::foo() has parameter $task with no value type specified in iterable type array.
     11: Dumped type: array&callable(): mixed
     12: Dumped type: class-string|object
    -13: Dumped type: string
    +13: Dumped type: non-falsy-string
    Full report
    Line Error
    8 Method MondayMorning::foo() has parameter $task with no value type specified in iterable type array.
    11 Dumped type: array&callable(): mixed
    12 `Dumped type: class-string
    13 Dumped type: non-falsy-string
  5. phpstan-bot commented on Apr 30, 2026

    @phpstan-bot
    Contributor

    @VincentLanglet After the latest push in 2.2.x, PHPStan now reports different result with your code snippet:

    @@ @@
      8: Method MondayMorning::foo() has parameter $task with no value type specified in iterable type array.
     11: Dumped type: array&callable(): mixed
     12: Dumped type: class-string|object
    -13: Dumped type: string
    +13: Dumped type: non-falsy-string
     15: Parameter #1 $task of method MondayMorning::call() expects array{object|string, int}, array&callable(): mixed given.
    Full report
    Line Error
    8 Method MondayMorning::foo() has parameter $task with no value type specified in iterable type array.
    11 Dumped type: array&callable(): mixed
    12 `Dumped type: class-string
    13 Dumped type: non-falsy-string
    15 `Parameter #1 $task of method MondayMorning::call() expects array{object
  6. phpstan-bot commented on May 7, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5573

  7. github-actions commented on Jun 8, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  8. locked as resolved and limited conversation to collaborators on Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions