Edit report at https://bugs.php.net/bug.php?id=65237&edit=1

 ID:                 65237
 Updated by:         a...@php.net
 Reported by:        jchan at malwarebytes dot org
 Summary:            Array Equality Bug
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   OSX & Linux Tested
 PHP Version:        5.3.26
 Block user comment: N
 Private report:     N

 New Comment:

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

array('apple','banana') == array(1 => 'banana',2=>'apple')

is the same as

array(0 => 'apple', 1 => 'banana') == array(1 => 'banana',2=>'apple')

So the doc won :)


Previous Comments:
------------------------------------------------------------------------
[2013-07-10 17:32:11] jchan at malwarebytes dot org

Description:
------------
When comparing 2 arrays in an if statement, array equality according to the 
documentation (http://www.php.net/manual/en/language.operators.array.php) does 
not 
work. According to the docs, order should not matter, but when comparing 2 
arrays 
directly it does.

Test script:
---------------
<?php

// based off of http://www.php.net/manual/en/language.operators.array.php

$a = array("apple", "banana");
$b = array(1 => "banana", "0" => "apple");


## WORKS ##
var_dump($a == $b); // bool(true)
var_dump($a === $b); // bool(false)
var_dump(array("apple", "banana") == array(1 => "banana", "0" => "apple")); // 
bool(true)


## FAILS? ##
if (array('apple','banana') == array(1 => 'banana',2=>'apple'))
   echo "they are equal.\n";
else
   echo "They are not equal.\n"; // this is the response I get

## yet if I do:
if ($a == $b)
   echo "they are equal.\n"; // this is the response I get...
else 
   echo "They are not equal.\n";



?>

Expected result:
----------------
bool(true)
bool(false)
bool(true)
they are equal.
they are equal.

Actual result:
--------------
bool(true)
bool(false)
bool(true)
They are not equal.
they are equal.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65237&edit=1

Reply via email to