Mantis - Quercus
Viewing Issue Advanced Details
2495 minor always 03-05-08 20:18 03-06-08 16:40
pablorg  
nam  
normal  
closed 3.1.5  
fixed  
none    
none 3.1.6  
0002495: strpos is broken
Strpos should return an int. If the needle is not found, it should return -1. You can easily reproduce the bug every time:

<?
$bob = "12345";
$pos = strpos($bob, "_");
echo "pos:$pos\n";
if ($pos > -1)
  echo "pos > -1 (ERROR)";
else
  echo "OK";
?>

Notes
(0002828)
etzel   
03-06-08 00:12   
You're wrong. Quoting official docs
"If needle is not found, strpos() will return >>>boolean<<< FALSE"

See http://ru2.php.net/manual/en/function.strpos.php [^]
(0002829)
pablorg   
03-06-08 06:12   
Agreed. PHP doesnt respect the docs. I'd like to close the bug, but Mantis doesnt give me the option.
(0002830)
nam   
03-06-08 06:42   
pablorg, you have a good point. In the PHP docs, they say that strpos may or may not return FALSE when the needle is not found (though I am not sure if we want to track down all the cases where PHP is not returning FALSE).

But in your test case, PHP's strpos does indeed return the type FALSE. The problem is that Quercus is evaulating 'FALSE > -1' as being true.
(0002831)
etzel   
03-06-08 08:30   
nam,
according to the current strpos source (http://lxr.php.net/source/php-src/ext/standard/string.c#2531), [^] it always returns boolean false (RETURN_FALSE) when the string is not found.
(0002832)
nam   
03-06-08 09:14   
Thanks etzel for the heads-up. At Caucho, we cannot look at the PHP source for copyright reasons. Our only references are PHP's behavior and the docs.
(0002834)
nam   
03-06-08 16:40   
Fixed 'FALSE > -1':

php/035p
php/035q