ID:               33422
 User updated by:  fjortiz at comunet dot es
 Reported By:      fjortiz at comunet dot es
-Status:           Bogus
+Status:           Open
 Bug Type:         Arrays related
 Operating System: Win2K Server
 PHP Version:      5.0.4
 New Comment:

ok, me again, I saw the 
"array_diff_assoc() requires that both the key and the value pairs
match."

so I guess PHP5 now considers both new Foo(5) objects as different
(PHP4.3 does bitwise comparison) so they are included in result array.


Still I find annoying that this breaks compatibility in some apps (it
certainly does in mine...). 

Any suggestions? Isn't there anything like "operator==" in C++, so I
can use array_diff_assoc safely (same key&value)? 

"PHP does not support operator overloading"

arrrg


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

[2005-06-21 17:00:30] [EMAIL PROTECTED]

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

This is expected behaviour, because objects in PHP5 are compared as
descriptors, i.e. even two identical objects of the same class are
different.

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

[2005-06-21 16:56:10] fjortiz at comunet dot es

Description:
------------
array_diff_assoc in PHP5 seems to ignore items whose values  are
objects. This should be irrelevant as this function takes only keys as
reference for comparison. See code.


Reproduce code:
---------------
class Foo       {
        var $dato;      
        function Foo($dato)     {
                $this->dato = $dato;    
        }
}

$array1 = array ("a" => new Foo(5), "b" => new Foo(2), "c" => "azul",
"rojo");
$array2 = array ("a" => new Foo(5), "amarillo", "rojo");
$result = array_diff_assoc ($array1, $array2);

print_r($result);

Expected result:
----------------
PHP 4.3.8:

Output:
Array
(
    [b] => foo Object
        (
            [dato] => 2
        )

    [c] => azul
    [0] => rojo
)

Correct.

The same code with PHP 5.0.4:
Output:
Array
(
    [a] => Foo Object
        (
            [dato] => 5
        )

    [b] => Foo Object
        (
            [dato] => 2
        )

    [c] => azul
    [0] => rojo
)

which is not the same, and not correct in PHP5: [a] item should not be
there.




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


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

Reply via email to