ID:               42341
 User updated by:  steven dot mccoy at miru dot hk
 Reported By:      steven dot mccoy at miru dot hk
 Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Ubuntu
 PHP Version:      5.2.4RC2
 New Comment:

Awesome, here's a possible compat function:

function compare_diff516($a, $b)
{
        if (is_object($a) || is_object($b))
                return $a == $b;
        return strcmp($a, $b);
}
function array_diff516($a, $b)
{
        return array_udiff($a, $b, 'compare_diff516');
}


Previous Comments:
------------------------------------------------------------------------

[2007-08-19 19:59:00] [EMAIL PROTECTED]

Expected behaviour -> bogus.

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

[2007-08-19 17:38:51] judas dot iscariote at gmail dot com

Use array_udiff with user supplied callback, the old behaviuor looks
wrong to me.

array_diff does compare with (string) $elem1 === (string) $elem2 and as
stdclass does not implement __toString() it emits a correct fatal error.

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

[2007-08-19 12:22:09] steven dot mccoy at miru dot hk

Description:
------------
Upgrading from PHP 5.1.6-1 (Debian) to 5.2.1 (Ubuntu) a regression has
appeared in array_diff().  Comparisons now fail when an array member is
a stdClass object.

Also reproduced with 5.2.4RC1-dev.

Reproduce code:
---------------
<?php
$dogs = array();
$poodle = new stdClass;
$poodle->collar = 'red';
array_push($dogs, $poodle);
array_push($dogs, 'terrier');
array_push($dogs, 'dalmation');

$cat = array('persian' => array(1, 2, 3));

var_dump(array_diff($dogs, $cat));
?>


Expected result:
----------------
array(3) {
  [0]=>
  object(stdClass)#1 (1) {
    ["collar"]=>
    string(3) "red"
  }
  [1]=>
  string(7) "terrier"
  [2]=>
  string(9) "dalmation"
}


Actual result:
--------------
Catchable fatal error: Object of class stdClass could not be converted
to string in /miru/home/steve-o/- on line 11


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


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

Reply via email to