Hi

Am 2024-09-02 15:24, schrieb Christoph M. Becker:
Now, comparing strstr() and strrchr() is of course still possible, but
different behavior is less astonishing. Of course, strrchr() could warn
or even throw if $needle has more than one character, but that may
unnecessarily break code for a small benefit.

I would expect that passing more than one character to `strrchr()` is very likely to be an accident or a misunderstanding of how the function behaves and thus already broken. A warning would just visibly point out that it is broken, instead of it silently behaving in a manner that diverges from the user's expectations (possibly unpredictably if the function is working on untrusted / user input).

If the function would be newly introduced, I'd make it an error to pass more than one character, but given that the function already exists, I'd say that pointing out such mistakes is exactly what the Warning / Notice facility is for.

Best regards
Tim Düsterhus

Reply via email to