Skip to content

Improve internal representation of ::class constants #3054

@muglug

Description

@muglug

Feature request

ConstantStringType::generalize has this logic:

https://github.com/phpstan/phpstan-src/blob/4d6904354ecd8df4f82e6b9b69925e4266d3f241/src/Type/Constant/ConstantStringType.php#L266-L273

This means that if you want to combine a list of possible strings into a single type, PHPStan will check every one to see if it could represent a class.

A better approach would be to create a separate ConstantClassStringType (or equivalent name).

Any Foo::class constant would have this type, and its generalize function would be simple, allowing you to strip the class-checking logic from ConstantStringType. It might change the behaviour of the program slightly, but it has a massive impact on PHPStan's memory consumption when evaluating large arrays

Ref #1275

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