Re: [PHP-DEV] array_diff() failures From: Stig Venaas (Stig.Venaas <email protected>)
Date: 12/28/00

Hi again

On Thu, Dec 28, 2000 at 07:58:40PM +0100, Stig Venaas wrote:
> Hi
>
> On Thu, Dec 28, 2000 at 11:42:22AM -0600, Andrei Zmievski wrote:
> > Stig,
> >
> > I've uncovered cases where array_diff() fails to produce the correct
> > result. I had two identical arrays (unsorted) and I ran array_diff() on
> > them, expecting to get an empty array back, but array_diff() did produce
> > some differences. This stems from the fact that you sort the arrays
> > yourself in the array_diff() and set the comparison function to
> > SORT_REGULAR. Since the regular comparison function is
> > non-deterministic, the arrays might be sorted differently depending on
> > the original order of the elements.

I've now removed array_type_data_compare and am using array_data_compare
with SORT_STRING. Seems to work well. Thanks for bringing this to my
attention. If you think there still are problems, let me know. There
were similar problems with array_unique() and array_intersect(), they
should also be okay now.

I don't like how SORT_REGULAR works and the fact that one can get
segfaults on Solaris with sort() etc. but I guess it's a bit drastic
to change it. Perhaps avoid the systems qsort when using SORT_REGULAR?
What do you think?

Stig

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>