vimeo/psalm
GitHub で見るpreg_replace_callback with PREG_UNMATCHED_AS_NULL flag results in `null` elements in callback
Open
#7,671 opened on 2022年2月14日
Help wantedgood first issue
Repository metrics
- Stars
- (5,369 stars)
- PR merge metrics
- (平均マージ 3d 12h) (30d で 5 merged PRs)
説明
The stub for preg_replace_callback() is:
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.