From:             jchan at malwarebytes dot org
Operating system: OSX & Linux Tested
PHP version:      5.3.26
Package:          *General Issues
Bug Type:         Bug
Bug description:Array Equality Bug

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 bug report at https://bugs.php.net/bug.php?id=65237&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=65237&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=65237&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=65237&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=65237&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=65237&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=65237&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=65237&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=65237&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=65237&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=65237&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=65237&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=65237&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=65237&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65237&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=65237&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=65237&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=65237&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65237&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=65237&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=65237&r=mysqlcfg

Reply via email to