Skip to content

Retain class_exists expression types in closure#5746

Merged
staabm merged 4 commits into
phpstan:2.1.xfrom
staabm:classe
May 24, 2026
Merged

Retain class_exists expression types in closure#5746
staabm merged 4 commits into
phpstan:2.1.xfrom
staabm:classe

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented May 24, 2026

analog #1929

class_exists() is special, because there's no way to unload a class in PHP, so it should "survive" when entering closure.

@staabm staabm requested a review from VincentLanglet May 24, 2026 09:25
@VincentLanglet
Copy link
Copy Markdown
Contributor

VincentLanglet commented May 24, 2026

Shouldnt be the same with trait exist and unterface exist and enum exists ?

Copy link
Copy Markdown
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be more place to check ?

  • MutatingScope::rememberConstructorExpressions: Check class_exists and function_exists but not other _exists function

  • MutatingScope::isInClassExists: Check class_exists, enum_exists, interface_exists ; seems ok according to the name of method at first sight but looking at ClassExistsFunctionTypeSpecifyingExtension we should maybe add enum_exists to be similar.

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented May 24, 2026

Might be more place to check ?

* MutatingScope::rememberConstructorExpressions: Check class_exists and function_exists but not other `_exists` function

agree - but I think these are problems for a separate PR

* MutatingScope::isInClassExists: Check class_exists, enum_exists, interface_exists ; seems ok according to the name of method at first sight but looking at `ClassExistsFunctionTypeSpecifyingExtension` we should maybe add enum_exists to be similar.

yeah need to be explored separately

@staabm staabm merged commit e71a222 into phpstan:2.1.x May 24, 2026
656 of 662 checks passed
@staabm staabm deleted the classe branch May 24, 2026 11:07
@VincentLanglet
Copy link
Copy Markdown
Contributor

VincentLanglet commented May 24, 2026

@staabm staabm mentioned this pull request May 24, 2026
@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented May 24, 2026

  • MutatingScope::rememberConstructorExpressions: Check class_exists and function_exists but not other _exists function

looked into it. I don't see a use-case yet, which would be improved when we remember also e.g. interface_exists, trait_exists or similar.

*_exist already implies class_exists, which means e.g. https://phpstan.org/r/46861d03-af49-45e5-b4ab-26d6a595c928 works as expected

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented May 24, 2026

  • MutatingScope::isInClassExists: Check class_exists, enum_exists, interface_exists ; seems ok according to the name of method at first sight but looking at ClassExistsFunctionTypeSpecifyingExtension
    we should maybe add enum_exists to be similar.

#5751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants