vimeo/psalm

preg_replace_callback with PREG_UNMATCHED_AS_NULL flag results in `null` elements in callback

Open

#7,671 创建于 2022年2月14日

在 GitHub 查看
 (10 评论) (0 反应) (0 负责人)PHP (668 fork)batch import
Help wantedgood first issue

仓库指标

Star
 (5,369 star)
PR 合并指标
 (平均合并 3天 12小时) (30 天内合并 5 个 PR)

描述

The stub for preg_replace_callback() is:

https://github.com/vimeo/psalm/blob/36d5a2a83c1d7b3e2aca1cfe9e9dcc916619e962/stubs/CoreGenericFunctions.phpstub#L922-L932

With @param callable(string[]):string $callback. However if you pass the PREG_UNMATCHED_AS_NULL flag the signature will become @param callable((string|null)[]):string $callback.

I have a $m[1] === null check in my callback function and now I get the errors:

ERROR: DocblockTypeContradiction - Cannot resolve types for $m[1] - docblock-defined type string does not contain null ERROR: RedundantConditionGivenDocblockType - Docblock-defined type string for $m[1] is never null

See https://psalm.dev/r/7537bf3352

https://3v4l.org/JdUaY shows the value of $m[1] is null.

贡献者指南