Skip to content

Commit 416e27b

Browse files
authored
ReverseSort bug, exposed but not caused by PHP8 (#1660)
Some tests of ReferenceHelper functions columnReverseSort and cellReverseSort which passed with PHP7 fail with PHP8. Both functions use the following construction: return 1 - strcasecmp(whatever); The "1" seems very mysterious. I believe that the correct code should be: return -strcasecmp(whatever); It appears in particular that PHP7 strcasecmp was never returning a value of 1 for the tests in question, but PHP8 strcasecmp does so. With the corrected code, the tests pass in both PHP7 and PHP8.
1 parent fe6221f commit 416e27b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/PhpSpreadsheet/ReferenceHelper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static function columnSort($a, $b)
6969
*/
7070
public static function columnReverseSort($a, $b)
7171
{
72-
return 1 - strcasecmp(strlen($a) . $a, strlen($b) . $b);
72+
return -strcasecmp(strlen($a) . $a, strlen($b) . $b);
7373
}
7474

7575
/**
@@ -108,7 +108,7 @@ public static function cellReverseSort($a, $b)
108108
[$bc, $br] = sscanf($b, '%[A-Z]%d');
109109

110110
if ($ar === $br) {
111-
return 1 - strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
111+
return -strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
112112
}
113113

114114
return ($ar < $br) ? 1 : -1;

0 commit comments

Comments
 (0)