Bug #65938 [NEW]: strpos('49,35',35) ==> FALSE

From: Date: Mon, 21 Oct 2013 14:43:04 +0000
Subject: Bug #65938 [NEW]: strpos('49,35',35) ==> FALSE
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182362@lists.php.net to get a copy of this message
From: runkharr at googlemail dot com Operating system: Linux PHP version: 5.5.5 Package: *General Issues Bug Type: Bug Bug description:strpos('49,35',35) ==> FALSE 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 bug report at https://bugs.php.net/bug.php?id=65938&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65938&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=65938&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65938&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65938&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65938&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65938&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65938&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65938&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65938&r=support Expected behavior: https://bugs.php.net/fix.php?id=65938&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65938&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65938&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65938&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65938&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65938&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65938&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65938&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65938&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65938&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65938&r=mysqlcfg

« previous php.bugs (#182362) next »