|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-09-14 07:10 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2015-09-14 07:10 UTC] requinix@php.net
[2019-06-28 18:48 UTC] allenmccabe at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 04:00:02 2025 UTC |
Description: ------------ The following test script is tested on PHP 5.4.43 (FreeBSD), PHP 5.5.20 (CentOS), PHP 5.6.10 (OSX). All tests say that "notHere" is in the array, and index 2. Before you say that the third parameter, "strict", will fix this. Consider: var_dump((int)'notHere' === 0); var_dump('notHere' === (string)0); I believe that it is the first casting that is being done internally in PHP? Would it not make more sense to cast it the other way around, as in no. 2? They look similar, but are completely different. In the first example I am searching for a string, "notHere". It's being casted to a integer (completely different value and type now), so it matches integer 0. In the second example I am still searching for a string, but now instead of casting the needle, the tested value is casted. The result of this comparison is false. Test script: --------------- <?php $data = ['str', 'str2', 0]; var_dump(in_array('notHere', $data)); var_dump(array_search('notHere', $data)); Expected result: ---------------- bool(false) bool(false) Actual result: -------------- bool(true) int(2)