From 43db94e94fb2f8bfce3d3d95405ae5204d684289 Mon Sep 17 00:00:00 2001 From: oleibman Date: Thu, 1 Oct 2020 02:24:53 -0700 Subject: [PATCH] Calculation/DateTime Failure With PHP8 (#1661) The following code generates an error with PHP8: if ($t1[1] > 29) { $t1[1] += 1900; Under the "right" conditions, PHP8 evaluates the condition as true when PHP8 is a non-numeric string and then generates an error trying to perform += on that non-numeric string. Adding a numeric test eliminates the problem. All unit tests involving this code now succeed with both PHP7 and PHP8. --- src/PhpSpreadsheet/Calculation/DateTime.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Calculation/DateTime.php b/src/PhpSpreadsheet/Calculation/DateTime.php index bfce2a02..4c2b108a 100644 --- a/src/PhpSpreadsheet/Calculation/DateTime.php +++ b/src/PhpSpreadsheet/Calculation/DateTime.php @@ -489,7 +489,7 @@ class DateTime if ($yearFound) { array_unshift($t1, 1); } else { - if ($t1[1] > 29) { + if (is_numeric($t1[1]) && $t1[1] > 29) { $t1[1] += 1900; array_unshift($t1, 1); } else {