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

Fix return type of array_search() with constant array type haystack #1806

Merged
merged 1 commit into from Dec 15, 2022

Conversation

takaram
Copy link
Contributor

@takaram takaram commented Oct 10, 2022

Return type of array_search() may be false unless we are sure that $haystack includes a value identical to $needle.

Closes phpstan/phpstan#3789

@staabm
Copy link
Contributor

staabm commented Oct 21, 2022

//cc @herndlm this will need manual conflict resolving with #1874

@takaram takaram changed the base branch from 1.8.x to 1.9.x November 5, 2022 13:06
Comment on lines 11 to 19
assertType('0|1|2|false', array_search($needle, $haystack, true));
assertType('0|1|2|false', array_search('foo', $haystack, true));

$haystack[1] = 'foo';
assertType('0|1|2|false', array_search($needle, $haystack, true));
assertType('0|1|2', array_search('foo', $haystack, true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add test-cases for the non-strict variant (leaving the 3rd param to false)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added test cases.

@ondrejmirtes ondrejmirtes merged commit b428afc into phpstan:1.9.x Dec 15, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@takaram takaram deleted the array-search-return-type branch February 24, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants