php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65938 strpos('49,35',35) ==> FALSE
Submitted: 2013-10-21 14:43 UTC Modified: 2013-10-21 14:50 UTC
From: runkharr at googlemail dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 5.5.5 OS: Linux
Private report: No CVE-ID: None
 [2013-10-21 14:43 UTC] runkharr at googlemail dot com
Description:
------------
strpos ($string, $number) returns FALSE, whereas
strpos ($string, (string) $number) returns the first occurrence of the (stringified) number. The same is true for older versions of PHP.

May be this is intended, but a small comment about this behaviour would be helpful.

The real problem is that (during the reading of configuration files or database values) sometimes an automatical conversion takes place, so that $number, which needs to be interpreted as a string in the example above, is instead interpreted as numerical value. This leads to problems in some programs, which (e.g.) search for a number in a comma-separated list of numbers.

Without knowing the behaviour of 'strpos()', one may sometimes search hours and hours for a problem which could be solved with a simple remark in the documentation.

Test script:
---------------
<?php
$a = '49,35'; $b = 35; $c = (string) $b;

print "strpos('$a', '$b') = ".strpos($a, $b)."\n";
print "strpos('$a', '$c') = ".strpos($a, $c)."\n";
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-21 14:50 UTC] runkharr at googlemail dot com
-Status: Open +Status: Closed
 [2013-10-21 14:50 UTC] runkharr at googlemail dot com
Sorry - sometimes i think i cannot read. This behaviour is documented, but i simply overlooked it ...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 00:01:33 2024 UTC