Skip to content

Commit ae6c285

Browse files
oleibmanGianluca Giovinazzo
authored and
Gianluca Giovinazzo
committed
Calculation/DateTime Failure With PHP8 (PHPOffice#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.
1 parent 5c22971 commit ae6c285

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/PhpSpreadsheet/Calculation/DateTime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ public static function DATEVALUE($dateValue = 1)
489489
if ($yearFound) {
490490
array_unshift($t1, 1);
491491
} else {
492-
if ($t1[1] > 29) {
492+
if (is_numeric($t1[1]) && $t1[1] > 29) {
493493
$t1[1] += 1900;
494494
array_unshift($t1, 1);
495495
} else {

0 commit comments

Comments
 (0)