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

Assignment within is_null() not taken into account. #4982

Closed
pauljherring opened this issue May 8, 2021 · 3 comments
Closed

Assignment within is_null() not taken into account. #4982

pauljherring opened this issue May 8, 2021 · 3 comments
Labels
Milestone

Comments

@pauljherring
Copy link

Bug report

Variable assignment within is_null() doesn't take into account the result of that is_null()

Code snippet that reproduces the problem

https://phpstan.org/r/a158f7de-7672-4860-a430-4beb421ae544

<?php declare(strict_types = 1);

/**
* @return array<mixed>|null
*/
function foo(){
	if (rand()<.5){
		return [1,2,3];
	}
	return null;
}

if (!is_null($c = foo())){
	echo count($c); // line 14
}

Output

14 | Parameter #1 $value of function count expects array\|Countable, array\|null given.

Expected output

No Errors!
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone May 8, 2021
@phpstan-bot
Copy link
Contributor

@pauljherring After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 (1 error)
-==========
-
-14: Parameter #1 $value of function count expects array|Countable, array|null given.
-
-PHP 7.1 – 7.4 (1 error)
-==========
-
-14: Parameter #1 $var of function count expects array|Countable, array|null given.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@b2bf703

@github-actions
Copy link

github-actions bot commented Jun 9, 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 Jun 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants