Skip to content

Fix get defined vars return type#4632

Merged
VincentLanglet merged 1 commit intophpstan:2.1.xfrom
VincentLanglet:fix/13881
Feb 9, 2026
Merged

Fix get defined vars return type#4632
VincentLanglet merged 1 commit intophpstan:2.1.xfrom
VincentLanglet:fix/13881

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet force-pushed the fix/13881 branch 2 times, most recently from 0501de2 to 43ebc5e Compare December 12, 2025 14:44
@VincentLanglet VincentLanglet marked this pull request as ready for review December 12, 2025 15:31
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

$typeBuilder = ConstantArrayTypeBuilder::createEmpty();

foreach ($scope->getDefinedVariables() as $variable) {
if ($variable === 'this') {
Copy link
Contributor

@staabm staabm Feb 9, 2026

Choose a reason for hiding this comment

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

just double checked: since regular variables cannot be named '$this' we don't need a inClassScope or similar check

https://3v4l.org/gSRUE#veol


its a open feature request that we don't error about such case atm: phpstan/phpstan#3585

Copy link
Contributor

Choose a reason for hiding this comment

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

I also though about moving this check directly into $scope->getDefinedVariables() but I would not do that because there might be extensions out there which depend on the behaviour that '$this' is returned atm

@VincentLanglet VincentLanglet merged commit a15babc into phpstan:2.1.x Feb 9, 2026
634 of 639 checks passed
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.

phpstan thinks get_defined_vars() contains "this", but it does not

3 participants