Skip to content

Commit ff2d004

Browse files
authored
Fix #19734: PHP 8.1 compatibility fix for $query->orderBy(null)
1 parent 581a7b2 commit ff2d004

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Yii Framework 2 Change Log
1414
- Enh #19689: Remove empty elements from the `class` array in `yii\helpers\BaseHtml::renderTagAttributes()` to prevent unwanted spaces (MoritzLost)
1515
- Chg #19696: Change visibility of `yii\web\View::isPageEnded` to `protected` (lubosdz, samdark)
1616
- Bug #19712: Cast shell_exec() output to string for jsCompressor (impayru)
17+
- Bug #19734: PHP 8.1 compatibility fix for `$query->orderBy(null)` (uaoleg)
1718
- Bug #19731: Fix `yii\data\Sort` to generate proper link when multisort is on and attribute has a default sort order set (bizley)
1819
- Bug #19735: Fix `yii\validators\NumberValidator` to use programmable message for the value validation (bizley)
1920

framework/db/QueryTrait.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ protected function isEmpty($value)
305305

306306
/**
307307
* Sets the ORDER BY part of the query.
308-
* @param string|array|ExpressionInterface $columns the columns (and the directions) to be ordered by.
308+
* @param string|array|ExpressionInterface|null $columns the columns (and the directions) to be ordered by.
309309
* Columns can be specified in either a string (e.g. `"id ASC, name DESC"`) or an array
310310
* (e.g. `['id' => SORT_ASC, 'name' => SORT_DESC]`).
311311
*
@@ -358,12 +358,14 @@ public function addOrderBy($columns)
358358
/**
359359
* Normalizes format of ORDER BY data.
360360
*
361-
* @param array|string|ExpressionInterface $columns the columns value to normalize. See [[orderBy]] and [[addOrderBy]].
361+
* @param array|string|ExpressionInterface|null $columns the columns value to normalize. See [[orderBy]] and [[addOrderBy]].
362362
* @return array
363363
*/
364364
protected function normalizeOrderBy($columns)
365365
{
366-
if ($columns instanceof ExpressionInterface) {
366+
if (empty($columns)) {
367+
return [];
368+
} elseif ($columns instanceof ExpressionInterface) {
367369
return [$columns];
368370
} elseif (is_array($columns)) {
369371
return $columns;

0 commit comments

Comments
 (0)