-
Notifications
You must be signed in to change notification settings - Fork 666
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
str_replace does not allow a null replacement #3224
Comments
I found these snippets: https://psalm.dev/r/89bd6bab25<?php
echo str_replace('a', null, 'abc');
|
Looks like a sufficiently bad code that should be fixed rather than allowed. |
I agree that it's bad in that it would not have crossed my mind to write it that way, but it feels like Psalm is overstepping here... this looks like something that phpcs would forbid, but not Psalm. Psalm is here to find bugs, and this works perfectly, doesn't it? |
That's debatable. On one hand 'Psalm is not PhpCS' is established position, I had the issues reported by me closed with that justification. On the other hand Psalm rejects a lot of perfectly working code (see all those Mixed* issues), so it's not here to only prevent bugs. It's here to make you write better code, and does this mainly by enforcing type correctness. And you're passing Besides, it's easy to fix: https://psalm.dev/r/1d16bdfe2a |
I found these snippets: https://psalm.dev/r/1d16bdfe2a<?php
echo str_replace('a', (string)null, 'abc');
|
Again, I did not write this :P , but if I had to fix it, I would use I'm afraid that if I change this, people are going to go pedantic and tell me that nothing in the docs says that replacement as to be
I didn't know that was the case, closing, then, thank you. |
Apart from the function description which reads 'Replace all occurrences of the search string with the replacement string' (https://www.php.net/str_replace). If that doesn't work to convince them, invoke @Ocramius 🤣 |
Well the repo at hand is doctrine/dbal, so … should work I guess :P |
should be fixed: use a |
It's fixed, see the linked commit above ;) |
Working php code Psalm is not happy with: https://psalm.dev/r/89bd6bab25
I would fix it but I could not find where Psalm gets its info from.
The text was updated successfully, but these errors were encountered: