#39278 [Opn->Bgs]: strpos($needle, $integer) returns 0 for certain values of $integer

From: Date: Fri, 27 Oct 2006 11:19:17 +0000
Subject: #39278 [Opn->Bgs]: strpos($needle, $integer) returns 0 for certain values of $integer
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-104070@lists.php.net to get a copy of this message
ID: 39278 Updated by: tony2001@php.net Reported By: matt at raines dot me dot uk -Status: Open +Status: Bogus Bug Type: Strings related Operating System: GNU/Linux 2.4.27 PHP Version: 5.1.6 New Comment: If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. Hint: chr(65) == 'A', chr(66) == 'B' Previous Comments: ------------------------------------------------------------------------ [2006-10-27 11:13:08] matt at raines dot me dot uk Description: ------------ Searching for a string in an integer using strpos() returns integer 0 if (integer % 256) is the lowest ASCII value of any character in the search string, or the highest ASCII value of any character minus 256. Otherwise it returns boolean false as expected. Reproduce code: --------------- var_dump(strpos("A", 65)); var_dump(strpos("A", 66)); var_dump(strpos("B", 65)); var_dump(strpos("B", 66)); Expected result: ---------------- bool(false) bool(false) bool(false) bool(false) Actual result: -------------- int(0) bool(false) bool(false) int(0) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39278&edit=1

« previous php.bugs (#104070) next »