From 00441ce44d26a5f5bcf7741d8c1323aac8597688 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Mon, 24 Jun 2024 08:18:01 +0000 Subject: [PATCH] Fix: PHP 8.3 deprecation error for `strcmp` with a `null` second argument https://datatables.net/forums/discussion/79256 --- Editor/Options.php | 17 ++++++++++++++--- Editor/SearchBuilderOptions.php | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Editor/Options.php b/Editor/Options.php index fa940cf..01202d9 100644 --- a/Editor/Options.php +++ b/Editor/Options.php @@ -334,9 +334,20 @@ public function exec($db) // Only sort if there was no SQL order field if (!$this->_order) { usort($out, static function ($a, $b) { - return is_numeric($a['label']) && is_numeric($b['label']) ? - ($a['label'] * 1) - ($b['label'] * 1) : - strcmp($a['label'], $b['label']); + $aLabel = $a['label']; + $bLabel = $b['label']; + + if ($aLabel === null) { + $aLabel = ''; + } + + if ($bLabel === null) { + $bLabel = ''; + } + + return is_numeric($aLabel) && is_numeric($bLabel) ? + ($aLabel * 1) - ($bLabel * 1) : + strcmp($aLabel, $bLabel); }); } diff --git a/Editor/SearchBuilderOptions.php b/Editor/SearchBuilderOptions.php index 500be20..73c3553 100644 --- a/Editor/SearchBuilderOptions.php +++ b/Editor/SearchBuilderOptions.php @@ -323,9 +323,20 @@ public function exec($field, $editor, $http, $fields, $leftJoinIn) // Only sort if there was no SQL order field if (!$this->_order) { usort($out, static function ($a, $b) { - return is_numeric($a['label']) && is_numeric($b['label']) ? - ($a['label'] * 1) - ($b['label'] * 1) : - strcmp($a['label'], $b['label']); + $aLabel = $a['label']; + $bLabel = $b['label']; + + if ($aLabel === null) { + $aLabel = ''; + } + + if ($bLabel === null) { + $bLabel = ''; + } + + return is_numeric($aLabel) && is_numeric($bLabel) ? + ($aLabel * 1) - ($bLabel * 1) : + strcmp($aLabel, $bLabel); }); }