Skip to content

More precise types in class constants #3530

@jbafford

Description

@jbafford

Bug report

An array of class names is not properly detected as class-string.

Code snippet that reproduces the problem

https://phpstan.org/r/e84c46b3-64d2-4326-aa7a-7881f44b2c25

phpstan reports that a method that expects class-string is given string.

Expected output

phpstan should return no error via either of the two following mechanisms:

  • the constant is explicitly defined as having values of class-string<someinterface> via an annotation, which phpstan ignores (class-string not enforced in constants #2798)
  • the constant contains values of class-string, which phpstan can normally infer, but because it has 10 elements, which exceeds CONSTANT_SCALAR_UNION_THRESHOLD, phpstan does not make the inference.

While I would prefer this fixed via fixing #2798 (which would fix this general case entirely), if increasing CONSTANT_SCALAR_UNION_THRESHOLD is the solution you prefer, I should be able to make a PR that adds a configuration option to set it.

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