Edit report at https://bugs.php.net/bug.php?id=61326&edit=1
ID: 61326 Updated by: cataphr...@php.net Reported by: aim at secoya dot dk Summary: ArrayObject comparison -Status: Open +Status: Assigned Type: Bug Package: SPL related Operating System: Windows 7 x64 PHP Version: 5.3.10 -Assigned To: +Assigned To: cataphract Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2012-03-08 15:23:57] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61326&edit=1