Bug #65938 [Opn->Csd]: strpos('49,35',35) ==> FALSE
| From: | runkharr at googlemail dot com | Date: | Mon, 21 Oct 2013 14:50:27 +0000 |
| Subject: | Bug #65938 [Opn->Csd]: strpos('49,35',35) ==> FALSE | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182363@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65938&edit=1
ID: 65938
User updated by: runkharr at googlemail dot com
Reported by: runkharr at googlemail dot com
Summary: strpos('49,35',35) ==> FALSE
-Status: Open
+Status: Closed
Type: Bug
Package: *General Issues
Operating System: Linux
PHP Version: 5.5.5
Block user comment: N
Private report: N
New Comment:
Sorry - sometimes i think i cannot read. This behaviour is documented, but i simply overlooked it
...
Previous Comments:
------------------------------------------------------------------------
[2013-10-21 14:43:04] 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";
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65938&edit=1