kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
557 stars 302 forks source link

PHP 7.2 sorting with 'DESC' and 'ASC' raises error #1025

Closed tsdogs closed 2 years ago

tsdogs commented 2 years ago

With PHP 7.2 (suspect 7.4 too) and version 3.5.0 if the Data Provider has a sort which is defined as [ 'field' => 'DESC' ]

it raises an error for the sorting icon: 2022-03-23 11:11:36 [93.34.237.144][7][-][error][yii\base\ErrorException:8] yii\base\ErrorException: Undefined index: DESC in /var/www/html/vendor/kartik-v/yii2-grid/src/DataColumn.php:311 Stack trace:

0 /var/www/html/vendor/kartik-v/yii2-grid/src/DataColumn.php(311): yii\base\ErrorHandler->handleError(8, 'Undefined index...', '/var/www/html/ve...', 311, Array)

Chainging it to [ 'fileld' => SORT_DESC ] fixes the problem (which probably is the correct way of doing it anyway).

Problem is that somehow with PHP 8.x (which I use for development) this does not happen (could not figure out exactly why) and php 7.2 stared doing it with new version of yii2-grid (it worked just fine before). So it's somehow a regression.

kartik-v commented 2 years ago

Your issue, is not related to the extension but is a Yii2 standard. Yes you need to change it to SORT_DESC and SORT_ASC as that is the recommended way for Yii2 Data Provider sort handling.