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

[0.12.83] remembering and forgetting returned values feature doesn't take side effects into account #4797

Closed
jacekkarczmarczyk opened this issue Apr 3, 2021 · 4 comments

Comments

@jacekkarczmarczyk
Copy link

Bug report

This can be quite tricky. Some functions may have side effects so that remembering return value doesn't make sense if next actions mutates the state

Code snippet that reproduces the problem

if (file_exists('foo')) {
	unlink('foo');
	if (file_exists('foo')) {
		echo "File still exists although it was deleted";
	}
}

https://phpstan.org/r/61c5bd5b-dc64-4562-aa3c-49cf7de51992

Expected output

No error

@dktapps
Copy link
Contributor

dktapps commented Apr 3, 2021

It doesn't make sense in this case anyway, because file_exists() depends on filesystem state (e.g. if the file was deleted, the result might change). Because it depends on state, file_exists() should be considered to have side effects itself.

@ondrejmirtes
Copy link
Member

PHPStan currently requires you to call clearstatcache between the calls: https://phpstan.org/r/8a78a20f-7d2c-4863-812d-9347933aa159

What I haven't noticed is this sentence in PHP manual:

However unlink() clears the cache automatically.

So I'll fix this scenario.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@63d0670

@github-actions
Copy link

github-actions bot commented May 5, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants