vimeo/psalm

str_replace with a polymorphic subject returns string

Open

#7.625 geöffnet am 10. Feb. 2022

Auf GitHub ansehen
 (7 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)PHP (668 Forks)batch import
Help wantedbugeasy problemsgood first issuetype providers

Repository-Metriken

Stars
 (5.369 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 3T 12h) (5 gemergte PRs in 30 T)

Beschreibung

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

Contributor Guide