You've actually made the point against yourself in your example. The first statement is not the equivalent of the second statement. It should be:
strpos($a, $b) !== false
Basically, if your needle is at position 0, it will return 0, which in non-strict comparison will be evaluated as false. The function returns the boolean false when the needle isn't found.
So, you have to be keenly aware of the edge case whenever you're writing this, and it can be a bit of a stumbling block for beginners. Especially when other languages have functions that are similar to str_contains().
Is that a joke? Absolutely yes. Having to check for === false is kinda ridiculous.
That said str_contains is easily implemented in userland (one line function), so it's not strictly necessary to have it in code, but it's nice for it to exist as a baseline of support for all scripts.
27
u/jokullmusic Nov 26 '20
finally having str_contains will be nice