Bug #62977 [Asn]: array_unique() misbehaves with array of DateTimes
Edit report at https://bugs.php.net/bug.php?id=62977edit=1 ID: 62977 Updated by: cataphr...@php.net Reported by:ladislav at marek dot su Summary:array_unique() misbehaves with array of DateTimes Status: Assigned Type: Bug Package:Class/Object related Operating System: Linux PHP Version:5.4Git-2012-08-30 (Git) Assigned To:laruence Block user comment: N Private report: N New Comment: laruuence: The patch is very strange. Why are making all the elements of the same class being compared equal? Objects can be compared. Perhaps you should fix the DateTime's compare_objects() object handler. Previous Comments: [2012-08-30 15:52:05] larue...@php.net The following patch has been added/updated: Patch Name: bug62977.patch Revision: 1346341925 URL: https://bugs.php.net/patch-display.php?bug=62977patch=bug62977.patchrevision=1346341925 [2012-08-30 13:24:49] ladislav at marek dot su Description: array_unique() returns duplicates for array which contains objects with DateTime instances. Test script: --- ?php class Foo { public $dt; function __construct($dt) { $this-dt = $dt; } } $foo = new Foo(new DateTime); $std = new stdClass; $arr = [$foo, $foo, $std, $std, $std]; var_dump(array_unique($arr, SORT_REGULAR)); Expected result: array(4) { [0]= object(Foo)#1 (1) { [dt]= object(DateTime)#2 (3) { [date]= string(19) 2012-08-30 15:18:01 [timezone_type]= int(3) [timezone]= string(13) Europe/Prague } } [2]= object(stdClass)#3 (0) { } } Actual result: -- array(4) { [0]= object(Foo)#1 (1) { [dt]= object(DateTime)#2 (3) { [date]= string(19) 2012-08-30 15:18:01 [timezone_type]= int(3) [timezone]= string(13) Europe/Prague } } [1]= object(Foo)#1 (1) { [dt]= object(DateTime)#2 (3) { [date]= string(19) 2012-08-30 15:18:01 [timezone_type]= int(3) [timezone]= string(13) Europe/Prague } } [2]= object(stdClass)#3 (0) { } [4]= object(stdClass)#3 (0) { } } -- Edit this bug report at https://bugs.php.net/bug.php?id=62977edit=1
Bug #62977 [Asn]: array_unique() misbehaves with array of DateTimes
Edit report at https://bugs.php.net/bug.php?id=62977edit=1 ID: 62977 Updated by: larue...@php.net Reported by:ladislav at marek dot su Summary:array_unique() misbehaves with array of DateTimes Status: Assigned Type: Bug Package:Class/Object related Operating System: Linux PHP Version:5.4Git-2012-08-30 (Git) Assigned To:laruence Block user comment: N Private report: N New Comment: Cataphrac, that's why I didn't commit it, and the reason is because the comparable calss are not neighbouring after sorting. that's not much thing to do with the compare handler of specific handler. thanks Previous Comments: [2012-08-30 17:27:44] cataphr...@php.net laruuence: The patch is very strange. Why are making all the elements of the same class being compared equal? Objects can be compared. Perhaps you should fix the DateTime's compare_objects() object handler. [2012-08-30 15:52:05] larue...@php.net The following patch has been added/updated: Patch Name: bug62977.patch Revision: 1346341925 URL: https://bugs.php.net/patch-display.php?bug=62977patch=bug62977.patchrevision=1346341925 [2012-08-30 13:24:49] ladislav at marek dot su Description: array_unique() returns duplicates for array which contains objects with DateTime instances. Test script: --- ?php class Foo { public $dt; function __construct($dt) { $this-dt = $dt; } } $foo = new Foo(new DateTime); $std = new stdClass; $arr = [$foo, $foo, $std, $std, $std]; var_dump(array_unique($arr, SORT_REGULAR)); Expected result: array(4) { [0]= object(Foo)#1 (1) { [dt]= object(DateTime)#2 (3) { [date]= string(19) 2012-08-30 15:18:01 [timezone_type]= int(3) [timezone]= string(13) Europe/Prague } } [2]= object(stdClass)#3 (0) { } } Actual result: -- array(4) { [0]= object(Foo)#1 (1) { [dt]= object(DateTime)#2 (3) { [date]= string(19) 2012-08-30 15:18:01 [timezone_type]= int(3) [timezone]= string(13) Europe/Prague } } [1]= object(Foo)#1 (1) { [dt]= object(DateTime)#2 (3) { [date]= string(19) 2012-08-30 15:18:01 [timezone_type]= int(3) [timezone]= string(13) Europe/Prague } } [2]= object(stdClass)#3 (0) { } [4]= object(stdClass)#3 (0) { } } -- Edit this bug report at https://bugs.php.net/bug.php?id=62977edit=1
Bug #62977 [Asn]: array_unique() misbehaves with array of DateTimes
Edit report at https://bugs.php.net/bug.php?id=62977edit=1 ID: 62977 Updated by: larue...@php.net Reported by:ladislav at marek dot su Summary:array_unique() misbehaves with array of DateTimes Status: Assigned Type: Bug Package:Class/Object related Operating System: Linux PHP Version:5.4Git-2012-08-30 (Git) Assigned To:laruence Block user comment: N Private report: N New Comment: fixing this we should introduce a new sorting function for objects which will make the nearest objects be neighbourings after sorting, leaving the comparing to the unique phase. but the problem is how to implement the nearest (equal same ce not equal) Previous Comments: [2012-08-31 03:41:56] larue...@php.net Cataphrac, that's why I didn't commit it, and the reason is because the comparable calss are not neighbouring after sorting. that's not much thing to do with the compare handler of specific handler. thanks [2012-08-30 17:27:44] cataphr...@php.net laruuence: The patch is very strange. Why are making all the elements of the same class being compared equal? Objects can be compared. Perhaps you should fix the DateTime's compare_objects() object handler. [2012-08-30 15:52:05] larue...@php.net The following patch has been added/updated: Patch Name: bug62977.patch Revision: 1346341925 URL: https://bugs.php.net/patch-display.php?bug=62977patch=bug62977.patchrevision=1346341925 [2012-08-30 13:24:49] ladislav at marek dot su Description: array_unique() returns duplicates for array which contains objects with DateTime instances. Test script: --- ?php class Foo { public $dt; function __construct($dt) { $this-dt = $dt; } } $foo = new Foo(new DateTime); $std = new stdClass; $arr = [$foo, $foo, $std, $std, $std]; var_dump(array_unique($arr, SORT_REGULAR)); Expected result: array(4) { [0]= object(Foo)#1 (1) { [dt]= object(DateTime)#2 (3) { [date]= string(19) 2012-08-30 15:18:01 [timezone_type]= int(3) [timezone]= string(13) Europe/Prague } } [2]= object(stdClass)#3 (0) { } } Actual result: -- array(4) { [0]= object(Foo)#1 (1) { [dt]= object(DateTime)#2 (3) { [date]= string(19) 2012-08-30 15:18:01 [timezone_type]= int(3) [timezone]= string(13) Europe/Prague } } [1]= object(Foo)#1 (1) { [dt]= object(DateTime)#2 (3) { [date]= string(19) 2012-08-30 15:18:01 [timezone_type]= int(3) [timezone]= string(13) Europe/Prague } } [2]= object(stdClass)#3 (0) { } [4]= object(stdClass)#3 (0) { } } -- Edit this bug report at https://bugs.php.net/bug.php?id=62977edit=1