ID:               44444
 Updated by:       [EMAIL PROTECTED]
 Reported By:      pawel dot jacek dot matysiak at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Windows XP
 PHP Version:      5.2.5
 New Comment:

Says the documentation:
"array_unique() sorts the values treated as string at first, then will
keep the first key encountered for every value, and ignore all following
keys. It does not mean that the key of the first related value from the
unsorted array will be kept."

"Note: Two elements are considered equal if and only if (string) $elem1
=== (string) $elem2. In words: when the string representation is the
same. The first element will be used."

Then, this isn't a bug.

<?php

class foo { 
        public function __toString() {
                return 'Hi';
        }
}

var_dump(array_unique(array(new foo, new foo)));

/*
array(1) {
  [0]=>
  object(foo)#1 (0) {
  }
}
*/


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

[2008-03-16 12:33:29] pawel dot jacek dot matysiak at gmail dot com

Description:
------------
I've encountered a problem when working with array of objects and using
mentioned library function array_unique. It just doesn't work.

Reproduce code:
---------------
<?php
class Test
{
        public $x;
        public function __construct($x)
        {
                $this->x = $x;
        }
}
$temp[] = new Test(1);
$temp[] = new Test(1);
var_dump($temp);
$temp2 = array_unique($temp);
var_dump($temp2);
?>

Expected result:
----------------
I expected the function to return the array with only one object. It
could return unchanged array but I think it would not make any sense.



Actual result:
--------------
error: Catchable fatal error: Object of class Test could not be
converted to string in test.php on line 13


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


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

Reply via email to