|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-19 12:22 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 13:00:01 2025 UTC |
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'); }