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

More precise return type for mysqli_fetch_all() #3778

Open
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from

Conversation

oxan
Copy link

@oxan oxan commented Jan 10, 2025

mysqli_fetch_all() and mysqli_result::fetch_all() returns a sequentially indexed array (list) of arrays, so convert its return type from array to list<array>.

The fullly specified return type for these functions is a bit more complicated, as it depends on the $mode parameter:

  • If it's MYSQLI_ASSOC, it's a list of associative arrays, i.e. list<array<string, string|int|float|null>>.
  • If it's MYSQLI_NUM, it's a list of lists, i.e. list<list<array|int|float|null>>.
  • If it's MYSQLI_BOTH, it's a list of enumerated and associative arrays, i.e. list<array<string|int, string|int|float|null>>.

We could specify the return type as list<array<string|int, string|int|float|null>> to catch all these cases, but I'm not sure that'd be very helpful, as it might force users to deal with types in the union that will never happen in their case. The mysqli_fetch_array() and mysqli_result::fetch_array() functions that share the same polymorphic behaviour are also typehinted as just array.

I think the CI failure is unrelated.

@oxan oxan force-pushed the patch-1 branch 3 times, most recently from 3ab861f to 945e142 Compare January 13, 2025 09:16
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.

1 participant