2015-02-24 17:36 GMT+01:00 Benjamin Eberlei <[email protected]>:
> Hi,
>
> On Tue, Feb 24, 2015 at 5:17 PM, Thomas Gielfeldt <[email protected]>
> wrote:
>
>> Hi internals.
>>
>> I've made PR proposing a feature request: A new interface Sortable.
>>
>> https://github.com/php/php-src/pull/1116
>>
>> If possible, I would like to create and RFC describing this in more
>> detail,
>> and perhaps get a voting on.
>>
>
> so you need to implement all methods? This can probably be considered a
> violation of the Interface Segregation Principle. But adding an interface
> for each method seems a bit much as well.
>
>>
>>
Another solution could be:
/** @ingroup SPL
* @brief This Interface allows to hook into the global Xsort() functions.
* @since PHP 5.6
*/
interface Sortable
{
/**
* Sort the entries by values.
*
* @param integer $sort_flags
* SORT_REGULAR: compare items normally (don't change types)
* SORT_NUMERIC: compare items numerically
* SORT_STRING: compare items as strings
* SORT_LOCALE_STRING: compare items as strings, based on the current
locale. It uses the locale, which can be changed using setlocale()
* SORT_NATURAL: compare items as strings using "natural
ordering" like natsort()
* SORT_FLAG_CASE: can be combined (bitwise OR) with SORT_STRING or
SORT_NATURAL to sort strings case-insensitively
* SORT_FLAG_REVERSE: can be combined (bitwise OR) with any of the
other options to sort in reverse
*/
function sort($sort_flags = SORT_REGULAR);
/** Sort the entries by values using user defined function.
*/
function usort(mixed cmp_function);
}
/** @ingroup SPL
* @brief This Interface allows to hook into the global XaXsort() functions.
* @since PHP 5.6
*/
interface SortableAssoc
{
/**
* Sort the entries by values and maintain indexes.
*
* @param integer $sort_flags
* SORT_REGULAR: compare items normally (don't change types)
* SORT_NUMERIC: compare items numerically
* SORT_STRING: compare items as strings
* SORT_LOCALE_STRING: compare items as strings, based on the current
locale. It uses the locale, which can be changed using setlocale()
* SORT_NATURAL: compare items as strings using "natural
ordering" like natsort()
* SORT_FLAG_CASE: can be combined (bitwise OR) with SORT_STRING or
SORT_NATURAL to sort strings case-insensitively
* SORT_FLAG_REVERSE: can be combined (bitwise OR) with any of the
other options to sort in reverse
*/
function asort($sort_flags = SORT_REGULAR);
/** Sort the entries by values using user defined function and maintain
index.
*/
function uasort(mixed cmp_function);
}
/** @ingroup SPL
* @brief This Interface allows to hook into the global XkXsort() functions.
* @since PHP 5.6
*/
interface SortableKeys
{
/**
* Sort the entries by key.
*
* @param integer $sort_flags
* SORT_REGULAR: compare items normally (don't change types)
* SORT_NUMERIC: compare items numerically
* SORT_STRING: compare items as strings
* SORT_LOCALE_STRING: compare items as strings, based on the current
locale. It uses the locale, which can be changed using setlocale()
* SORT_NATURAL: compare items as strings using "natural
ordering" like natsort()
* SORT_FLAG_CASE: can be combined (bitwise OR) with SORT_STRING or
SORT_NATURAL to sort strings case-insensitively
* SORT_FLAG_REVERSE: can be combined (bitwise OR) with any of the
other options to sort in reverse
*/
function ksort($sort_flags = SORT_REGULAR);
/** Sort the entries by key using user defined function.
*/
function uksort(mixed cmp_function);
}
I have a working implementation of this also.
> Thanks
>>
>> Br,
>>
>> Thomas Gielfeldt
>>
>
>