I think the reason is in the PHP Source usort
and array_uintersect
and other similar user callback compare function which is php_array_user_compare
xref: /PHP_5_3/ext/standard/array.c
568static int php_array_user_compare(const void *a, const void *b TSRMLS_DC) /* {{{ */
569{
570 Bucket *f;
571 Bucket *s;
572 zval **args[2];
573 zval *retval_ptr = NULL;
574
575 f = *((Bucket **) a);
576 s = *((Bucket **) b);
577
578 args[0] = (zval **) f->pData;
579 args[1] = (zval **) s->pData;
580
581 BG(user_compare_fci).param_count = 2;
582 BG(user_compare_fci).params = args;
583 BG(user_compare_fci).retval_ptr_ptr = &retval_ptr;
584 BG(user_compare_fci).no_separation = 0;
585 if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && retval_ptr) {
586 long retval;
587
588 convert_to_long_ex(&retval_ptr);
589 retval = Z_LVAL_P(retval_ptr);
590 zval_ptr_dtor(&retval_ptr);
591 return retval < 0 ? -1 : retval > 0 ? 1 : 0;
592 } else {
593 return 0;
594 }
595}
This uses retval
which is an integer to compare the function if you look at
retval < 0 ? -1 : retval > 0 ? 1 : 0
If you are using using Boolean and conversion is required it can only give 0
or 1
Example
var_dump((int) true); // 1
var_dump((int) false); // 0
This means that you might be able to get away with boolean
during intersect because only where $a === $b = 0
is required but not for other implementations where retval < 0
-1
,0
and1
are actually typical sorting criteria. – inhan Nov 10 '12 at 2:24