Re: [RFC] enum SortDirection
| From: | Larry Garfield | Date: | Tue, 03 Mar 2026 00:36:00 +0000 |
| Subject: | Re: [RFC] enum SortDirection | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130230@lists.php.net to get a copy of this message | ||
On Mon, Mar 2, 2026, at 4:14 PM, Derick Rethans wrote:
> On 2 March 2026 21:43:19 GMT, Bob Weinand <bobwei9@hotmail.com> wrote:
>>Hey Tim,
>>
>>On 2.3.2026 21:45:39, Tim Düsterhus wrote:
>>> Hi
>>>
>>> please consider this email as a formal request for comments on my modest proposal of
>>> adding a new
enum SortDirection to PHP’s standard library.
>>>
>>> I have made the full proposal available on the World Wide Web at:
>>>
>>> https://wiki.php.net/rfc/sort_direction_enum
>>>
>>> Yours sincerely
>>> Tim Düsterhus
>>
>>
>>That's a good idea, but I wouldn't introduce such class without some usages at
>>least.
>>
>>I'd recommend considering immediately upgrading the proposed functions to use
>>SortDirection and redefine the constants in terms of the enum.
>>
>>I.e. set const SORT_ASC = SortDirection::Ascending; - similar for others like the
>>SCANDIR_SORT_DESCENDING etc..
>>
>>This is a reasonable BC break, which is also trivially fixed by simply accepting
>>int|SortDirection in existing functions.
>
>
>
> If its a BC break, it can't go into a 8.× for something that isn't *necessary*.
>
> But I also don't see how accepting both int and this new enum for
> existing built-in functions is a BC break.
>
> Changing the existing constants to something else is probably not a
> good idea, as other user functions or libraries might have reused them..
>
> cheers
> Derick
I concur. I'd like to see the functions updated now in the RFC, so we get a sense of how many
functions will be impacted. Not because I'm concerned about a widened type breaking anything,
but more so readers can see the value this brings.
The Yii DB layer (at least in v2, I haven't used v3 yet) used SORT_ASC/SORT_DESC for itself, so
I agree that redefining those is unwise.
Nit: Should we use Asc and Desc, for more compact code? Enums are great, but they can get verbose
at times. :-) (SortDirection::Descending is 25 characters long, for what is ultimately a named
boolean.)
On the whole, though, I'm in favor.
--Larry Garfield