PHP 4.0 Bug #2682: Function strpos have a problem with pos 0 and false
| From: | rehr at supermall dot dk | Date: | Mon, 08 Nov 1999 08:39:48 +0000 |
| Subject: | PHP 4.0 Bug #2682: Function strpos have a problem with pos 0 and false | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-12210@lists.php.net to get a copy of this message | ||
From: rehr@supermall.dk
Operating system: Linux Redhat 6.0
PHP version: 4.0 Beta 2
PHP Bug Type: Other
Bug description: Function strpos have a problem with pos 0 and false
<?
$haystack = "123456789";
$needle = "1";
$tmp = strpos($haystack,$needle);
if ($tmp)
{
printf("Yes");
}
else
{
printf("No");
}
?>
This prints no, because it returns 0 which is the same as false.
The documentation says:
If needle is not found, returns false.
The problem if needle is at position 0 i haystack then it returns 0 which seems to be the same as
false, therefore if needle is at position 0
you get the same result as if it is not in haystack at all.
I don't know if this is a bug or just something that should be mentioned in the documentation.
Feel free to mail me.
Regards
Martin.