$strstr(,needle) returns nothing, whereas I would expect it to return 0 as does $strstr(haystack,needle), given
Help
$strstr(x,y) Finds the first occurrence of string y in string x.
Is this a known bug?
$strstr(,needle) returns nothing, whereas I would expect it to return 0 as does $strstr(haystack,needle), given
Help
$strstr(x,y) Finds the first occurrence of string y in string x.
Is this a known bug?
If I remember correctly from the good ole BASIC times the strstr-function (there called "instr") always produced a runtime error if the first string was empty or shorter than the second string. So one (the programmer) had to make sure that the function was let loose on a valid combination.
Years if not decades have passed since ... apparently the function still requires a little common sense.
Which result would you have expected as IMHO checking "nothing" for the presence of a string should not produce the same result as finding that a string is definitely not part of another string? Something that can be expressed by a division by zero?
I am not sure, if it is a bug or a lack of information due to missing documentation.
See yourself ...
DD.20110710.2058.CEST
Your mean the function definition requires a little common sense?
It should. If the y is not in x, the result should be zero regardless of the value of x.
Since this cannot be fixed in $strstr fixed without breaking script compatibility, can we please have a $strstr2 in which it is fixed?
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.