Added warning for bad return values from user comparators
Alerts users that comparators should be in the style of functions passed to e.g. C qsort (i.e. returning -1, 0, or 1) rather than STL-style boolean comparators (i.e. true for less-than).
Esse commit está contido em:
@@ -239,6 +239,7 @@ struct ElmUCompare {
|
||||
typedef typename AccessorT::ElmT ElmT;
|
||||
AccessorT acc;
|
||||
const CallCtx* ctx;
|
||||
ElmUCompare() : warned(false) {}
|
||||
bool operator()(ElmT left, ElmT right) const {
|
||||
Variant ret;
|
||||
TypedValue args[2];
|
||||
@@ -260,9 +261,11 @@ struct ElmUCompare {
|
||||
default: /* fall through */ break;
|
||||
}
|
||||
}
|
||||
// Task #1839416: Raise a warning indicating that the comparator
|
||||
// returned something other than an integer, double, or numeric
|
||||
// string
|
||||
if (!warned) {
|
||||
raise_warning("Sort comparators should return an integer, double, "
|
||||
"or numeric string with value -1, 0, or 1");
|
||||
warned = true;
|
||||
}
|
||||
if (ret.isBoolean()) {
|
||||
// Match the behavior of Zend PHP for comparators that return
|
||||
// boolean values
|
||||
@@ -283,6 +286,8 @@ struct ElmUCompare {
|
||||
}
|
||||
return ret.toInt64() < 0;
|
||||
}
|
||||
private:
|
||||
mutable bool warned;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário