The current type-stubs for pg_fetch_all are as follows:
/**
* @return array<int, array>
* @refcount 1
*/
#[\Since('8.1')]
function pg_fetch_all(\PgSql\Result $result, int $mode = PGSQL_ASSOC): array
{
}
(See https://github.com/phpstan/php-8-stubs/blob/1f23686dca88ed6d9a96c673d16ce11a16746af4/stubs/ext/pgsql/pg_fetch_all.php)
But as far as I can tell, pg_fetch_all actually returns list<array>. I've tried to verify this by looking through the pg_fetch_all source, and I'm quite sure it will always return a list, but it's a bit too dense for me to be certain.
I've also run the following assert on our codebase, and at least for all our queries, it true:
$data = pg_fetch_all($result);
assert(array_is_list($data));
Side-note: this is much less important, but would it in theory be possible to do something like the following, to further restrict the type?
/**
* @return ($mode is PGSQL_NUM
* ? list<list<string|null>>
* : ($mode is PGSQL_ASSOC
* ? list<array<string, ?null>>
* : list<array<array-key, ?string>>
* )
* )
*/
The current type-stubs for
pg_fetch_allare as follows:(See https://github.com/phpstan/php-8-stubs/blob/1f23686dca88ed6d9a96c673d16ce11a16746af4/stubs/ext/pgsql/pg_fetch_all.php)
But as far as I can tell,
pg_fetch_allactually returnslist<array>. I've tried to verify this by looking through the pg_fetch_all source, and I'm quite sure it will always return alist, but it's a bit too dense for me to be certain.I've also run the following assert on our codebase, and at least for all our queries, it true:
Side-note: this is much less important, but would it in theory be possible to do something like the following, to further restrict the type?