Skip to content

Invalidate array type info when using array_{push,pop,shift,unshift}#101

Merged
ondrejmirtes merged 1 commit intophpstan:masterfrom
cs278:issue-2750
Jan 14, 2020
Merged

Invalidate array type info when using array_{push,pop,shift,unshift}#101
ondrejmirtes merged 1 commit intophpstan:masterfrom
cs278:issue-2750

Conversation

@cs278
Copy link
Copy Markdown
Contributor

@cs278 cs278 commented Jan 14, 2020

Fixes phpstan/phpstan#2750

Seems to me like it's probably worth something more generic like - if the method has side effects and argument is passed by reference invalidate the argument.

@cs278 cs278 requested a review from ondrejmirtes January 14, 2020 21:21
@ondrejmirtes
Copy link
Copy Markdown
Member

Something like that is already done here:

if ($assignByReference) {
$argValue = $arg->value;
if ($argValue instanceof Variable && is_string($argValue->name)) {
$scope = $scope->assignVariable($argValue->name, new MixedType());
}
}

Thank you! PR makes perfect sense. Maybe we could call invalidateExpression inside specifyExpressionType but I'm not sure if should always be done and which additional cases it'd solve. But it seems logical.

@ondrejmirtes ondrejmirtes merged commit b1fd47b into phpstan:master Jan 14, 2020
@cs278 cs278 deleted the issue-2750 branch January 15, 2020 08:40
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.

array_shift() does not reset array count bounds

2 participants