Closed jubianchi closed 10 years ago
(CC @paroski)
Thanks for reporting this. This is an intentional difference. We make the assumption, for performance reasons, that sort comparator functions are transitive.
In other words, if $a < $b
and $b < $c
then $a < $c
. Your first callback violates this constraint, since if $a
, $b
and $c
are all distinct then $a < $b
and $b < $c
and $c < $a
.
Your second callback is transitive so we end up performing the comparisons you expect.
I got different result with
array_uintersect_uassoc
between PHP and HHVM while working on @atoum.In @atoum, we use
array_uintersect_uassoc
to compare arrays with the same callback used to compare values and keys. This callback only will return only two values :0
if values (or keys) are equal (==
) and-1
if they are different.With PHP, this works fine but with HHVM, the keys comparaison seems to fail. I had to write a dedicated callback for keys which returns 3 values :
0
if values are equal,-1
if$a
is lower than$b
and 1 otherwise.I reproduced this use case in a tiny PHP test (I don't know if I should commit this one and where I should put it but I would be glad to open a PR):
Running this script, we get the following results :
It seems there is the same inconsistency with
array_intersect_uassoc
.