php / doc-en

English PHP documentation
502 stars 732 forks source link

strpos() and stripos() changed behavior under 8.x that is not documented #1927

Open syntaxler opened 2 years ago

syntaxler commented 2 years ago

While porting code to php 8.1 I have noticed that strpos() and stripos() return index 0 under php 8.x when searching for the empty string "" as needle in any haystack, while 7.x returned false under this circumstances. As far as I have seen this is not mentioned in the documentation of these functions, and also not in https://www.php.net/manual/en/migration80.incompatible.php

This change in behavior breaks code, please add it to the documentation.

cmb69 commented 2 years ago

It is mentioned in https://www.php.net/manual/en/migration80.incompatible.php:

The needle argument for strpos(), strrpos(), stripos(), strripos(), strstr(), stristr() and strrchr() can now be empty.

This needs to be added to the changelog of these functions.

syntaxler commented 2 years ago

Needle could always be empty, just the return value changed. I would suggest explaining in the docs what "The needle argument can now be empty" means in practise, that is having to check for the empty string every single time you use one of these functions if the needle could be empty, which it often times can.

japorter commented 11 months ago

This has not been added to stristr() changelog.

Girgias commented 11 months ago

This has not been added to stristr() changelog.

Done in d369659c3ffdc8b60f3958b587eea94e6e867fec