vimeo/psalm

str_replace with a polymorphic subject returns string

Open

#7625 aperta il 10 feb 2022

Vedi su GitHub
 (7 commenti) (0 reazioni) (0 assegnatari)PHP (668 fork)batch import
Help wantedbugeasy problemsgood first issuetype providers

Metriche repository

Star
 (5369 star)
Metriche merge PR
 (Merge medio 3g 12h) (5 PR mergiate in 30 g)

Descrizione

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

Guida contributor