Skip to content

Improve str_replace return type #4242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from

Conversation

andersonamuller
Copy link

@andersonamuller andersonamuller commented Aug 13, 2025

When the config checkBenevolentUnionTypes is enabled the str_replace starts to always reporting the return as string|list<string> but in reality the return depends on the $subject param type.

@staabm
Copy link
Contributor

staabm commented Aug 13, 2025

which error is this PR trying to solve? can you reproduce the error/problem on phpstan.org/try ?

@andersonamuller
Copy link
Author

andersonamuller commented Aug 13, 2025

How can I create a try reproducible with the config checkBenevolentUnionTypes enabled?
https://phpstan.org/r/e850992d-7494-49b0-9ccb-0af488bd1710

@staabm
Copy link
Contributor

staabm commented Aug 13, 2025

I see. you cannot set a config flag on phpstan.org/try.

please add a test-case in ReturnTypeRuleTest which fails without your fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants