array_unique() and object comparison

From: Date: Tue, 13 Aug 2013 10:15:12 +0000
Subject: array_unique() and object comparison
Groups: php.internals 
Request: Send a blank email to internals+get-68499@lists.php.net to get a copy of this message
array_unique() is perfect for removing duplicates in a string array, but not so great for an array of objects. SORT_REGULAR was added to compare items without casting them to string. However it uses the "==" comparison operator. I see two improvements: - on a short term, improve the documentation to make it explicit that the "==" operator will be used (the example with "(string) $elem1 === (string) $elem2" is misleading, "===" should be replaced with "==") - on a long term, maybe add another option SORT_STRICT (like the $strict parameter for in_array): that sort would use the strict comparison operator "===" Any thoughts about that? Matthieu

« previous php.internals (#68499) next »