Skip to content

How can I let phpstan know that a string contains the name of a class of a given type? #5019

Discussion options

You must be logged in to vote

Hi,
this works: https://phpstan.org/r/bdd8200a-b3cb-49c6-8c09-675aca255411

Which means that for your original example to work, a slight change needs to be done in PHPStan internals, around this place: https://github.com/phpstan/phpstan-src/blob/18f8473fa5c8e957f5e24d25961160ac89afd506/src/Analyser/NodeScopeResolver.php#L2070 (same logic needs to be executed in the $expr->name instanceof Expr branch as here).

Feel free to tackle this problem, or open a bug report.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@mind-bending-forks
Comment options

@mind-bending-forks
Comment options

@ondrejmirtes
Comment options

@mind-bending-forks
Comment options

@ondrejmirtes
Comment options

Answer selected by ondrejmirtes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants