php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39278 strpos($needle, $integer) returns 0 for certain values of $integer
Submitted: 2006-10-27 11:13 UTC Modified: 2006-10-27 11:19 UTC
From: matt at raines dot me dot uk Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.1.6 OS: GNU/Linux 2.4.27
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: matt at raines dot me dot uk
New email:
PHP Version: OS:

 

 [2006-10-27 11:13 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-27 11:19 UTC] tony2001@php.net
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'
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 13:01:33 2025 UTC