php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61326 ArrayObject comparison
Submitted: 2012-03-08 15:23 UTC Modified: 2012-03-10 17:19 UTC
From: aim at secoya dot dk Assigned: cataphract (profile)
Status: Closed Package: SPL related
PHP Version: 5.3.10 OS: Windows 7 x64
Private report: No CVE-ID: None
 [2012-03-08 15:23 UTC] aim at secoya dot dk
Description:
------------
When constructing ArrayObjects by passing arrays to their constructor subsequent 
object comparisons do not return the right result.

Only by using getArrayCopy, we get the proper result.

Test script:
---------------
<?php
$a = array();
$b = array();
$a[] = 0;
$b[] = 0;
echo '$a==$b                .. ';
var_dump($a==$b);
$b[] = 1;
echo '$b[] = 1; $a==$b      .. ';
var_dump($a==$b);
$a_o = new ModifiedArrayObject($a);
$b_o = new ModifiedArrayObject($b);
echo '$a_o==$b_o            .. ';
var_dump($a_o==$b_o);
echo '$a_o->compareTo($b_o) .. ';
var_dump($a_o->compareTo($b_o));


class ModifiedArrayObject extends ArrayObject {
	public function compareTo(ArrayObject $a) {
		$to = $a->getArrayCopy();
		return $this->getArrayCopy() == $to;
	}
}


Expected result:
----------------
$a_o == $b_o returns false.

Actual result:
--------------
$a_o == $b_o returns true.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-09 02:27 UTC] aharvey@php.net
-Package: SPL_Types +Package: SPL related
 [2012-03-10 15:40 UTC] cataphract@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: cataphract
 [2012-03-10 17:19 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=324082
Log: - Fixed bug #61326 (ArrayObject comparison).
 [2012-03-10 17:19 UTC] cataphract@php.net
-Status: Assigned +Status: Closed
 [2012-03-10 17:19 UTC] cataphract@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-04-18 09:45 UTC] laruence@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=23e65a9dcc71cf11ee5ec82c256588626545d4db
Log: - Fixed bug #61326 (ArrayObject comparison).
 [2012-07-24 23:36 UTC] rasmus@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=23e65a9dcc71cf11ee5ec82c256588626545d4db
Log: - Fixed bug #61326 (ArrayObject comparison).
 [2013-11-17 09:33 UTC] laruence@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=23e65a9dcc71cf11ee5ec82c256588626545d4db
Log: - Fixed bug #61326 (ArrayObject comparison).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC