Skip to content

Empty string issue for strpos(), strrpos(), stripos(), strripos(), strstr(), strchr(), strrchr(), and stristr()  #8582

@dmitrirussu

Description

@dmitrirussu

Description

Hi following your documentation on php 8.0 I found some incompatibilities, I would like to understand what is the reason of returning position "0" for empty string when "$haystack" is not empty... what issue you are solving here?

I would like to argue it is a buggy stuff and nothing more...

The following code:

// let suppose we have next 
$haystack = "test";
$needle = "";

$haystack === $needle // => "false"  will result in false because $haystack  is not empty string
stripos($haystack, $needle) // => "0" how do you get this :), is "$haystack" an empty string where is logic, why not keep return "false"

//on position "0" we have latter "t"

"t" === "" // => false,  could you please argue here .... I still could not understood
// you have empty pointer in memory until '$haystack = ""', if "$haystack" is not empty then no any pointer in memory for that empty value... 

//If I do search for empty string then I'm expecting "$haystack" to be empty string.... I'm not expecting you to find a void point on the beginning of string or on end of string, middle of string... 

//Could you please provide how many bytes takes empty char into "$haystack = 'test'"? I would say nothing, if nothing  then should be false returned

I would expect next:

stripos("test",  "") // => false
 stripos("",  "") // => 0 or false as it was before




### PHP Version

PHP 8.0

### Operating System

ubuntu

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions