ID: 30419 User updated by: m dot konings at knowmany dot nl Reported By: m dot konings at knowmany dot nl Status: Bogus Bug Type: Strings related Operating System: Windows XP SP2 PHP Version: 4.3.8 New Comment:
Thanks for the explanation. Although I feel that in this case the documenation should reflect that strpos() takes a mixed needle variable type, not a string. There are lots of other PHP functions that take mixed variable types as parameter, and for those, the manual states so in the function declaration. Previous Comments: ------------------------------------------------------------------------ [2004-10-13 09:24:24] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php See the manual (http://php.net/strpos): If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. ------------------------------------------------------------------------ [2004-10-13 08:20:31] m dot konings at knowmany dot nl Description: ------------ When I use a integer variable as needle to the strpos() function, the needle is not found. Reproduce code: --------------- <? $str_haystack = '12345'; $str_needle = '3'; $int_haystack = 12345; $int_needle = 3; $test = strpos($str_haystack, $str_needle); var_dump($test); $test = strpos($str_haystack, $int_needle); var_dump($test); $test = strpos($int_haystack, $str_needle); var_dump($test); $test = strpos($int_haystack, $int_needle); var_dump($test); ?> Expected result: ---------------- Due to the fact the strpos() is declared as int strpos ( string haystack, string needle [, int offset] ) I would expect that using a integer as needle would cause a implicit type cast to string. This does not seem to be the case, because using an integer as needle for strpos() will always return false (bool). Actual result: -------------- The call to strpos() with the integer needle return false (bool), while the call to strpos() with string needles return the actual position within the haystack. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30419&edit=1