php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34976 Strange return values from strpos when inside foreach
Submitted: 2005-10-25 10:40 UTC Modified: 2005-10-25 11:00 UTC
From: mikael at chl dot chalmers dot se Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.4.0 OS: Linux
Private report: No CVE-ID: None
 [2005-10-25 10:40 UTC] mikael at chl dot chalmers dot se
Description:
------------
When using strpos inside a foreach and the needle is the key of the array being looped over one get strange return values. Not all key and not all length of the haystack produces this result, and not all needle/haystacks produce the same faulty return value

Reproduce code:
---------------
$maps = array('919400' => 'foo');
foreach ($maps as $orgnr => $foo)
	var_dump(strpos('ou=000000,ou=000000,ou=000000,ou=0000000000,ou=organization,dc=chalmers,dc=se', $orgnr));


Expected result:
----------------
bool(false)

Actual result:
--------------
int(64)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-25 11:00 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."
In your case needle is int(919400). 
chr(919400) returns "h", so you got what you was looking for: "h" is 65-th symbol in your string.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 09:01:31 2024 UTC