Skip to content

Utilized SortDirection enum from PHP 8.6#580

Open
okorneliuk wants to merge 4 commits into
thephpleague:masterfrom
okorneliuk:sort-direction-enum
Open

Utilized SortDirection enum from PHP 8.6#580
okorneliuk wants to merge 4 commits into
thephpleague:masterfrom
okorneliuk:sort-direction-enum

Conversation

@okorneliuk

@okorneliuk okorneliuk commented Jun 25, 2026

Copy link
Copy Markdown

Related to #579

Added a polyfill of upcoming PHP 8.6, used SortDirection enum from it instead of private constants in Column. Slightly extended public API so it is possible to use SortDirection directly in sortOn method.

@nyamsprod

Copy link
Copy Markdown
Member

@okorneliuk thanks for the PR. While it would be nice to have this inside the package. The CSV package is meant to be used without dependencies so the best course of action would be to update this PR by including the polyfill directly inside the package.


declare(strict_types=1);

if (!enum_exists('SortDirection', false)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simply use PHP_VERSION_ID it is simple and fast

<?php

if (PHP_VERSION_ID < 80600) {
    enum SortDirection
    {
        case Ascending;
        case Descending;
    }
}

@okorneliuk okorneliuk Jun 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If polyfill is already defined by another library in the project, we will probably get an exception of trying to redefine the enum. I prefer to keep this as it is.

Comment thread polyfill/sort_direction.php
Comment thread composer.json Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants