Bug #76994 [NEW]: in_array/array_search unexpected result
From: luigi dot gualtieri at gmail dot com
Operating system: WIN + LINUX
PHP version: 7.0.32
Package: Arrays related
Bug Type: Bug
Bug description:in_array/array_search unexpected result
Description:
------------
This is the scenario:
- the needle is a string that starts with a numeric content (eg: "45x")
- haystack contains a numeric item that match the numeric part of the
needle (eg: ["23", 34, 45, "abc"]
in_array function returns true and array_search function returns
int(2).
Test script:
---------------
<?php
$needle = '45x';
$haystack = ["23", 34, 45, "abc"];
//$test = 'g\'"';
//$test_array = ["g"];
$result = in_array($needle, $haystack );
var_dump($result);
$result = array_search($needle, $haystack );
var_dump($result);
Expected result:
----------------
functions have to return false
Actual result:
--------------
in_array: bool(true)
array_search: int(2)
--
Edit bug report at https://bugs.php.net/bug.php?id=76994&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76994&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76994&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76994&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76994&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76994&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76994&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76994&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76994&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76994&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76994&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76994&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76994&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76994&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76994&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76994&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76994&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76994&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76994&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76994&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76994&r=mysqlcfg
Thread (4 messages)
- luigi dot gualtieri at gmail dot com