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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 10:01:27 2025 UTC