From:             m dot konings at knowmany dot nl
Operating system: Windows XP SP2
PHP version:      4.3.8
PHP Bug Type:     Strings related
Bug description:  strpos does not autocast integer needles

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 bug report at http://bugs.php.net/?id=30419&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30419&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30419&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30419&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30419&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30419&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30419&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30419&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30419&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30419&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30419&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=30419&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=30419&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30419&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30419&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30419&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30419&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30419&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30419&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30419&r=mysqlcfg

Reply via email to