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

Invalid argument supplied when condition is stored in variable #1209

Closed
simPod opened this issue Jul 11, 2018 · 5 comments
Closed

Invalid argument supplied when condition is stored in variable #1209

simPod opened this issue Jul 11, 2018 · 5 comments
Labels

Comments

@simPod
Copy link
Contributor

simPod commented Jul 11, 2018

	/**
	 * @param mixed[]|string $value
	 */
	public function sayHello($value): void
	{
		$isArray = is_array($value);
		if($isArray){
			foreach($value as $x){
				
			}
		}

	}

Argument of an invalid type array|string supplied for foreach, only iterables are supported.

https://phpstan.org/r/a2c25c03288fbfc18c7d0a7cb6460764

@JanTvrdik
Copy link
Contributor

This is currently expected behavior. Supporting this would require for the static analyzer to prove that the previously computed type guards have not been invalidated at point where they are used, i.e. sth like

$isArray = is_array($value);
$value = 123;
if ($isArray) {
	foreach($value as $x) {
	}
}

@simPod
Copy link
Contributor Author

simPod commented Jul 12, 2018

makes sense, thx

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Jul 12, 2018 via email

@ondrejmirtes ondrejmirtes added this to the Dependent types milestone Jul 13, 2018
@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src@a9d5c8b

@github-actions
Copy link

github-actions bot commented May 3, 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 3, 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