php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64616 in_array comparison bug
Submitted: 2013-04-09 16:18 UTC Modified: 2013-04-09 18:53 UTC
From: spawnm at spawnm dot pl Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.4Git-2013-04-09 (Git) OS: ubuntu 12.10
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: spawnm at spawnm dot pl
New email:
PHP Version: OS:

 

 [2013-04-09 16:18 UTC] spawnm at spawnm dot pl
Description:
------------
PHP Version: 5.4.6-1ubuntu1.2

$arr = array ( 'error' => true );
echo in_array('lol', $arr)? 1: 0;//1
 
$arr = array ( 'error' => 'true' );
echo in_array('lol', $arr)? 1: 0;//0


Test script:
---------------
$arr = array ( 'error' => true );
echo in_array('lol', $arr)? 1: 0;//1
 
$arr = array ( 'error' => 'true' );
echo in_array('lol', $arr)? 1: 0;//0


Expected result:
----------------
$arr = array ( 'error' => true );
echo in_array('lol', $arr)? 1: 0;//1
 
$arr = array ( 'error' => 'true' );
echo in_array('lol', $arr)? 1: 0;//0

Actual result:
--------------
$arr = array ( 'error' => true );
echo in_array('lol', $arr)? 1: 0;//1
 
$arr = array ( 'error' => 'true' );
echo in_array('lol', $arr)? 1: 0;//0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-09 18:11 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-04-09 18:11 UTC] nikic@php.net
By default in_array uses == comparison (and true == 'lol'). If you want to use strict === comparison pass "true" as an additional parameter:

    in_array('lol', $arr, true);
 [2013-04-09 18:53 UTC] sixd@php.net
-Summary: bug +Summary: in_array comparison bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 05:01:30 2024 UTC