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

Add generic typings to array_uintersect #3806

Draft
wants to merge 2 commits into
base: 2.1.x
Choose a base branch
from

Conversation

axlon
Copy link
Contributor

@axlon axlon commented Feb 4, 2025

This PR adds generic typings to array_uintersect, I copied the annotations from array_udiff

@axlon
Copy link
Contributor Author

axlon commented Feb 4, 2025

This PR is a partial fix for phpstan/phpstan#7707, if this PR is the correct way to do this I can add support for the other functions mentioned as well

@axlon axlon marked this pull request as draft February 4, 2025 10:14
@axlon axlon marked this pull request as ready for review February 4, 2025 10:28
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

array $one,
array $two,
callable $three
): int {}
Copy link
Member

Choose a reason for hiding this comment

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

It'd be better to update the array_udiff and array_uintersect to actually use two different @template for each array (T + U).

@schlndh
Copy link
Contributor

schlndh commented Feb 7, 2025

@axlon BTW: The same fix is already implemented here: #3282

@axlon
Copy link
Contributor Author

axlon commented Feb 7, 2025

@axlon BTW: The same fix is already implemented here: #3282

I see, I missed this when looking through issues. However there's a slight difference in that the arrays can be different per @ondrejmirtes' suggestion.

The same issue with that PR is still present here; the definitions of these functions are wrong, but merging this would get us closer to PHPStan fully understanding these functions

@schlndh
Copy link
Contributor

schlndh commented Feb 7, 2025

@axlon You're right. Feel free to take whatever you want from the original PR, if you decide to expand this one to cover all similar functions. Alternatively, I'm also around to update my PR if ondrejmirtes prefers that.

array $one,
array $two,
callable $three
): int {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Both array_udiff and array_uintersect return an array, not int: https://3v4l.org/R0WNi

@axlon axlon marked this pull request as draft February 10, 2025 09:40
@axlon
Copy link
Contributor Author

axlon commented Feb 10, 2025

I'll try to take a look at this soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants