-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
PHP Drivers
-
None
-
None
-
None
-
None
-
None
-
None
The global SortDirection enum (provided by PHP 8.6 natively, or by symfony/polyfill-php86 for PHP 8.1 and later, with the cases Ascending and Descending) is used as a sort direction value by libraries such as the Doctrine MongoDB ODM. PHP cannot convert a SortDirection enum to an int, so each library and each user must manually map SortDirection::Ascending to 1 and SortDirection::Descending to -1 wherever a sort order is expected.
Request: BSON normalization should recognize a SortDirection enum and encode it as 1 for Ascending and -1 for Descending, so libraries and applications can pass the enum directly when building sort specifications.
Example
Before: the sort order must be provided as a literal 1 or -1.
$cursor = $collection->find([], [ 'sort' => ['createdAt' => 1, 'priority' => -1], ]);
After: the SortDirection enum is used directly and converted by the driver during BSON normalization.
$cursor = $collection->find([], [ 'sort' => ['createdAt' => SortDirection::Ascending, 'priority' => SortDirection::Descending], ]);
- related to
-
PHPLARA-274 laravel-mongodb - Issue #3506: Builder::orderBy() does not handle the new SortDirection enum from Laravel 13.8
-
- Closed
-
-
PHPLIB-1847 Support PHP 8.6 \SortDirection where a sort direction is expected
-
- Backlog
-
-
PHPC-2669 Test with PHP 8.6-dev
-
- Closed
-