doc-en icon indicating copy to clipboard operation
doc-en copied to clipboard

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

Open syntaxler opened this issue 2 years ago • 4 comments

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.

syntaxler avatar Nov 01 '22 15:11 syntaxler

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.

cmb69 avatar Nov 01 '22 15:11 cmb69

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.

syntaxler avatar Nov 01 '22 17:11 syntaxler

This has not been added to stristr() changelog.

japorter avatar Nov 17 '23 21:11 japorter

This has not been added to stristr() changelog.

Done in d369659c3ffdc8b60f3958b587eea94e6e867fec

Girgias avatar Nov 18 '23 04:11 Girgias