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

Regression when checking empty($array['key']) when 'key' is not optional #5258

Closed
ArtemGoutsoul opened this issue Jul 5, 2021 · 4 comments
Closed

Comments

@ArtemGoutsoul
Copy link

ArtemGoutsoul commented Jul 5, 2021

There's a regression in 0.12.91

If the key is optional, the !empty() check works as expected.

If the key is not optional, then !empty() check turns the type of the checked array into *NEVER*:

12 | Parameter #1 $params of static method HelloWorld::method2() expects array('other_key' => string), *NEVER* given.

https://phpstan.org/r/80cbdf06-2aa6-4d72-b5e6-0f816a9b5ed8

Possibly related to the fix for #3297, but not sure how :(

@ArtemGoutsoul
Copy link
Author

ArtemGoutsoul commented Jul 5, 2021

Tried to reproduce using tests:

	public function testBug5258(): void
	{
		$this->analyse([__DIR__ . '/data/bug-5258.php'], []);
	}
  • ran vendor/bin/paratest tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php
  • but I'm not getting
12 | Parameter #1 $params of static method HelloWorld::method2() expects array('other_key' => string), *NEVER* given.

@ondrejmirtes
Copy link
Member

Fixed, thanks! phpstan/phpstan-src@790a838

@ArtemGoutsoul
Copy link
Author

Thank you!! 🥳

@github-actions
Copy link

github-actions bot commented Aug 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 Aug 9, 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

2 participants