php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10658 array_diff does not work with classes
Submitted: 2001-05-04 03:36 UTC Modified: 2002-08-23 21:22 UTC
From: mihai dot negrea at spidernet dot co dot ro Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.0.5 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mihai dot negrea at spidernet dot co dot ro
New email:
PHP Version: OS:

 

 [2001-05-04 03:36 UTC] mihai dot negrea at spidernet dot co dot ro
Consider the following script:

<?
class test 
{
	var $x;
	var $y;
	
	function test ()
	{
		$this->x = 0;
		$this->y = 0;
	}
	
	function set ($x, $y)
	{
		$this->x = $x;
		$this->y = $y;
	}
	
}
$mumu = array();
$gaga = array();

for($i=0;$i<3;$i++)
{
	$test = new test ();
	$test->set($i, $i);
	$mumu["xx".$i] = $test;
}

for($i=0;$i<5;$i++)
{
	$test = new test ();
	$test->set($i, $i);
	$gaga["xx".$i] = $test;
}

$fff = array_diff($mumu, $gaga);
$ggg = array_diff($gaga, $mumu);

echo "<pre>";
print_r($fff);
echo "</pre>";

echo "<pre>";
print_r($ggg);
echo "</pre>";
?>



the following is the output from a server with php 
4.0.4pl1:
Array
(
)
Array
(
    [xx3] => test Object
        (
            [x] => 3
            [y] => 3
        )

    [xx4] => test Object
        (
            [x] => 4
            [y] => 4
        )

)


and the following is the ouput with php 4.0.5:
Array
(
)
Array
(
)

the php.ini is the same on both servers.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-14 19:32 UTC] jeroen@php.net
The problem is that array_diff compares the string-represantation of the arguments.

And in the case of objects, it is always "Object", and thus considered equal.

This is currently expected behaviour, though it'd be be better if it weren't... string-comparasation by array_diff & co is not satisfactionary in case of objects. (nor arrays)

Suspended.
 [2002-08-23 21:22 UTC] sniper@php.net
expected behaviour, not bug -> bogus.

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed May 22 13:01:28 2019 UTC