Skip to content

Conversation

oxan
Copy link
Contributor

@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
@ondrejmirtes ondrejmirtes merged commit b80968f into phpstan:2.1.x Mar 1, 2025
426 of 427 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

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.

2 participants