Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002495 [Quercus] minor always 03-05-08 20:18 03-06-08 16:40
Reporter pablorg View Status public  
Assigned To nam
Priority normal Resolution fixed  
Status closed   Product Version 3.1.5
Summary 0002495: strpos is broken
Description 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";
?>
Additional Information
Attached Files

- Relationships

- 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
 

- Issue History
Date Modified Username Field Change
03-05-08 20:18 pablorg New Issue
03-06-08 00:12 etzel Note Added: 0002828
03-06-08 06:12 pablorg Note Added: 0002829
03-06-08 06:42 nam Note Added: 0002830
03-06-08 06:43 nam Status new => assigned
03-06-08 06:43 nam Assigned To  => nam
03-06-08 08:30 etzel Note Added: 0002831
03-06-08 09:14 nam Note Added: 0002832
03-06-08 16:40 nam Status assigned => closed
03-06-08 16:40 nam Note Added: 0002834
03-06-08 16:40 nam Resolution open => fixed
03-06-08 16:40 nam Fixed in Version  => 3.1.6


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
40 total queries executed.
32 unique queries executed.
Powered by Mantis Bugtracker