note 116994 added to function.strpos
| From: | newartix at mail dot ru | Date: | Tue, 31 Mar 2015 11:30:38 +0000 |
| Subject: | note 116994 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202098@lists.php.net to get a copy of this message | ||
Extend (ohcc at 163 dot com)s comment:
Be careful when the $haystack or $needle parameter is an integer.
If you are not sure of its type, you should convert it into a string.
<?php
var_dump(strpos(12345,1));//false
var_dump(strpos(12345,'1'));//0
var_dump(strpos('12345',1));//false
var_dump(strpos('12345','1'));//0
$a = 12345;
$b = 1;
var_dump(strpos(strval($a),strval($b)));//0
var_dump(strpos((string)$a,(string)$b));//0
// and wait for interesting... CentOS 6.5 PHP-FPM 5.4.35
var_dump(strpos('mrwagon',626));//1 tadaaam!
?>
----
Server IP: 72.52.91.14
Probable Submitter: 5.128.118.165
----
Manual Page -- http://php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/116994
Del: integrated -- https://master.php.net/note/delete/116994/integrated
Del: useless -- https://master.php.net/note/delete/116994/useless
Del: bad code -- https://master.php.net/note/delete/116994/bad+code
Del: spam -- https://master.php.net/note/delete/116994/spam
Del: non-english -- https://master.php.net/note/delete/116994/non-english
Del: in docs -- https://master.php.net/note/delete/116994/in+docs
Del: other reasons-- https://master.php.net/note/delete/116994
Reject -- https://master.php.net/note/reject/116994
Search -- https://master.php.net/manage/user-notes.php