Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a variable by reference to a function and method has side effects #1990

Merged
merged 7 commits into from Jan 8, 2023

Conversation

ryium
Copy link
Contributor

@ryium ryium commented Nov 10, 2022

@ryium ryium marked this pull request as ready for review November 10, 2022 17:14
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Could you please test and fix other similar functions that might have the same issue? array_push, array_unshift, array_pop, array_splice

@ondrejmirtes
Copy link
Member

And maybe it'd be a better to idea to do this in public function hasSideEffects(): TrinaryLogic in various FunctionReflection and MethodReflection implementations - to return TrinaryLogic::createYes() if the function accepts parameters as references.

@ryium ryium changed the title Mark array_shift as having side effects Passing a variable by reference to a function and method has side effects Nov 12, 2022
{
public function run(array $arr): void
{
/** @var array{a: 0, b?: 1} $arr */
Copy link
Member

Choose a reason for hiding this comment

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

Hi, please put this type into @param above the method, here it's ambiguous what it means.

Also currently this example https://phpstan.org/r/de642079-e5b0-492a-9782-d78c324f70a7 shows Expression on left side of ?? is not nullable. so we'll need another test in NullCoalesceRuleTest to make sure this message goes away.

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, thank you for your review.
Added a test, but included a merge commit to follow the latest branch.
Should I recreate?

@ondrejmirtes ondrejmirtes merged commit 1070788 into phpstan:1.9.x Jan 8, 2023
@ondrejmirtes
Copy link
Member

Brought it over the finish line :) Thank you.

@ondrejmirtes
Copy link
Member

Sorry, I had to revert this, it led to some false positives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants