php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1398 wrong return value
Submitted: 1999-05-11 05:51 UTC Modified: 1999-05-11 07:55 UTC
From: thomas at intermezzo dot de Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.5 OS: Linux
Private report: No CVE-ID: None
 [1999-05-11 05:51 UTC] thomas at intermezzo dot de
$browser = "Mozilla";
if ( strpos($value, "Mozilla/") == 0)
{ ..... }

$browser = "Lynx";
if ( strpos($value, "Mozilla/") == 0)
{ ..... }


The function returns 0 , once because Mozilla is the first Character and secondly because Mozilla doesn't appear in "Lynx"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-05-11 07:55 UTC] sas at cvs dot php dot net
Your comparison is not correct. See http://www.php.net/manual/html/function.strpos.html

In short, strpos returns false, if the needle is not found. If you compare false with an integer, it is promoted to 0 and as such the expression in the if(...) construct is true.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 13 13:01:31 2024 UTC