php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67762 in_array evaluates as true when it should not
Submitted: 2014-08-04 23:30 UTC Modified: 2014-08-05 17:25 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: jv at vip dot ie Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2014-08-04 23:30 UTC] jv at vip dot ie
Description:
------------
---
From manual page: http://www.php.net/function.in-array
---

The result will output true, when it should output false.

Yup, this is a pretty fundamental bug ;)

Test script:
---------------
$correct_answers = array('meter');
$my_answer = 0;
echo in_array($my_answer, $correct_answers);

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

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-04 23:44 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-08-04 23:44 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

Fundamental bugs are easy to find when you don't read the documentation.

> Searches haystack for needle using loose comparison unless strict is set.
Loose comparison, where "meter" == 0.
If you want a strict comparison to get "meter" !== 0 then pass $strict=true.
 [2014-08-05 14:59 UTC] xjsv24 at gmail dot com
This looks like a bug to me. It breaks the transitive property.

if(0 == null) {
   echo "1<br>";
}

if(0 == "meter") {
   echo "2<br>";
}

if(null == "meter") {
   echo "3<br>";
}

Expected result:
----------------
1

Actual result:
--------------
1
2
 [2014-08-05 17:25 UTC] requinix@php.net
That would be loose typing and loose comparisons. Still not a bug.
http://php.net/manual/en/types.comparisons.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC