php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79216 in_array bug
Submitted: 2020-02-03 15:54 UTC Modified: 2020-02-03 16:56 UTC
From: uugv_tl at 163 dot com Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.2.27 OS: macos 10.15.3
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: uugv_tl at 163 dot com
New email:
PHP Version: OS:

 

 [2020-02-03 15:54 UTC] uugv_tl at 163 dot com
Description:
------------
$arr = array('b', 0); 
if(in_array('abc',$arr))
{
    echo 'ok';
}
else
{
    echo 'bad'
}

when above statement echo 'ok',shoud be echo 'bad' right?

Test script:
---------------
$arr = array('b', 0); 
if(in_array('abc',$arr))
{
    echo 'ok';
}
else
{
    echo 'bad'
}

shoud be echo 'bad',but echo 'ok'

Expected result:
----------------
'bad'

Actual result:
--------------
'ok'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-03 16:20 UTC] bugreports at gmail dot com
https://www.php.net/manual/en/language.types.type-juggling.php
https://www.php.net/manual/en/function.in-array.php

 strict

    If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack.
 [2020-02-03 16:55 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2020-02-03 16:55 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2020-02-03 16:56 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-02-03 16:56 UTC] cmb@php.net
Like stated in the comment above: you're hitting type-juggling.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 00:01:30 2024 UTC