Skip to content

2.3.0 regression: internal error with first-class method callable and closure in a generic array argument #15432

Description

@seansch

Bug report

After upgrading to PHPStan 2.3.0, analysis crashes with PHPStan\ShouldNotHappenException: Internal error. when a generic array argument contains both a first-class instance method callable and an anonymous function.

The exception originates in InitializerExprTypeResolver.php:743, with getFirstClassCallableType() and gatherArrayArgTypeSkeleton() in the stack trace.

I reproduced this without Laravel, Larastan, or other extensions, using PHP 8.5.11 at analysis level 8. The same code passes analysis with PHPStan 2.2.17 and executes successfully in PHP.

Assigning the method callable to a variable before placing it in the array avoids the crash in PHPStan 2.3.0.

Code snippet that reproduces the problem

https://phpstan.org/r/3ad3115b-59c2-46e6-b10c-5443aa613e71

Expected output

PHPStan should complete analysis without errors, as PHPStan 2.2.17 does for the same snippet. Both callbacks satisfy the declared parameter type, and the code executes successfully in PHP.

PHPStan 2.3.0 should produce the same result whether the method callable is placed directly in the array or assigned to a variable first. Neither form should cause an internal error.

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

PHPStan regularly catches issues before they reach production and gives me more confidence when refactoring. Thanks for all the work you put into it!

Activity

  1. added this to the Easy fixes milestone on Oct 8, 2026
  2. drewmt commented on Oct 8, 2026

    @drewmt

    Thanks for the reproducer. Fixed in phpstan/phpstan-src#6701. The regression covers direct and nested method callables alongside closures, and checks that incompatible callbacks still produce the expected error. The full PHP and Turbo suites pass locally; upstream CI is running.

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