Skip to content

Commit

Permalink
Calculation/DateTime Failure With PHP8 (PHPOffice#1661)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oleibman authored and Gianluca Giovinazzo committed Dec 14, 2020
1 parent 5c22971 commit ae6c285
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public static function DATEVALUE($dateValue = 1)
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 {
Expand Down

0 comments on commit ae6c285

Please sign in to comment.