Type-stubs for `pg_fetch_all` are incorrect

オープン 初心者向け
#155 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
php
領域
tooling

調査の方向性

stubs/ext/pgsql/pg_fetch_all.php から始め、php-src の ext/pgsql/pgsql.c#L2181 にあるリンク先の pg_fetch_all 実装と、その戻り値アノテーションを比較してください。結果が常にリストになるかを確認し、モード依存の精密化がスタブ形式でサポートされているかを判断したうえで、確認された動作に一致するようアノテーションを更新してください。

索引モデルが issue の本文から書いたものです。

説明

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>>
 *     )
 * )
 */
主要言語
PHP
スター
31
フォーク
12
平均マージ
1日 10時間
マージ済み PR(30日)
4

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

phpstan/php-8-stubs のほかの issue

phpstan/php-8-stubs の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。