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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: runkharr at googlemail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Mon Jun 02 21:01:27 2025 UTC