Type-stubs for `pg_fetch_all` are incorrect

未关闭 适合新手
#155 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
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 实现进行比较。确认结果是否始终为列表,判断 stub 格式是否支持依赖 mode 的细化,并更新注解,使其与已确认的行为一致。

由索引模型根据 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 小时
30 天内合并 PR
4

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

phpstan/php-8-stubs 的其他 Issue

查看 phpstan/php-8-stubs 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。