vimeo/psalm

str_replace with a polymorphic subject returns string

Open

#7 625 ouverte le 10 févr. 2022

Voir sur GitHub
 (7 commentaires) (0 réactions) (0 assignés)PHP (668 forks)batch import
Help wantedbugeasy problemsgood first issuetype providers

Métriques du dépôt

Stars
 (5 369 stars)
Métriques de merge PR
 (Merge moyen 3j 12h) (5 PRs mergées en 30 j)

Description

The return type of str_replace is deduced to be string when I pass it a $subject (the third parameter) of type string | array<string>. A $subject of type string leads to the string return type, while array<float | int | string> leads to array<string>, which is correct. It only incorrectly assumes string when the $subject is of a union type.

https://psalm.dev/r/48f8c3f020

Guide contributeur