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

Incorrect error if variable is passed as reference #1963

Closed
MartkCz opened this issue Mar 9, 2019 · 2 comments
Closed

Incorrect error if variable is passed as reference #1963

MartkCz opened this issue Mar 9, 2019 · 2 comments
Labels
Milestone

Comments

@MartkCz
Copy link

MartkCz commented Mar 9, 2019

https://phpstan.org/r/51b169ed-dff3-477d-a0c8-f6f2f9bcdd93

Code snippet that reproduces the problem

function test(array $array): string {
	if (!$array) {
		throw new \Exception('empty');
	}
	
	$shift = array_shift($array); // <- this is problem because of reference
	return $array ? 'has' : 'empty'; // <- error
}

var_dump(test(['first', 'second']));
var_dump(test(['first']));

Output is string(3) "has" string(5) "empty"

Phpstan outputs " 9 | Ternary operator condition is always true."

@ondrejmirtes
Copy link
Member

Will be fixed by #1964 once we figure out how to correctly change the typesystem.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Mar 9, 2019
@ondrejmirtes
Copy link
Member

Fixed: e937b16

@lock lock bot locked as resolved and limited conversation to collaborators Dec 23, 2019
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

2 participants