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.
This commit is contained in:
oleibman 2020-10-02 01:52:28 -07:00 committed by GitHub
parent fe6221fe49
commit 416e27b632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -69,7 +69,7 @@ class ReferenceHelper
*/ */
public static function columnReverseSort($a, $b) public static function columnReverseSort($a, $b)
{ {
return 1 - strcasecmp(strlen($a) . $a, strlen($b) . $b); return -strcasecmp(strlen($a) . $a, strlen($b) . $b);
} }
/** /**
@ -108,7 +108,7 @@ class ReferenceHelper
[$bc, $br] = sscanf($b, '%[A-Z]%d'); [$bc, $br] = sscanf($b, '%[A-Z]%d');
if ($ar === $br) { if ($ar === $br) {
return 1 - strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); return -strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
} }
return ($ar < $br) ? 1 : -1; return ($ar < $br) ? 1 : -1;