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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 00:01:41 2024 UTC