php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75329 in_array is REALLY not working
Submitted: 2017-10-06 17:45 UTC Modified: 2017-10-06 17:51 UTC
From: dutr4 at outlook dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: Windows/Linux
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: dutr4 at outlook dot com
New email:
PHP Version: OS:

 

 [2017-10-06 17:45 UTC] dutr4 at outlook dot com
Description:
------------
http://sandbox.onlinephpfunctions.com/code/661cc810693c8da8b987f4ca8ed9272375ab1e92

for eg

<?php
    $a = array('00', '000', 0);
    $ka = 'KA';
    var_dump(
        in_array($ka, $a)
    );

will always return true in ANY version of PHP, please, this error is probably breaking a lot of systems and sites!

Test script:
---------------
<?php
    $a = array('00', '000', 0);
    $ka = 'KA';
    var_dump(
        in_array($ka, $a)
    );


Expected result:
----------------
false

Actual result:
--------------
true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-06 17:48 UTC] peehaa@php.net
-Status: Open +Status: Not a bug
 [2017-10-06 17:48 UTC] peehaa@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

Without the 3rd param it will cast data. So it REALLY works as expected :-)
 [2017-10-06 17:50 UTC] peehaa@php.net
Check out what happens on 3v4l: https://3v4l.org/Ahkcs
 [2017-10-06 17:51 UTC] pollita@php.net
Congratulations, you have discovered weak type comparison.
This has been a feature of the language since day one, and as you say behaves consistently across all PHP versions.
If you're looking for a strict compare, please refer to third third paramter to http://php.net/in_array
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 13:01:33 2025 UTC