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.
This commit is contained in:
oleibman 2020-10-01 02:24:53 -07:00 committed by GitHub
parent 9683e5be18
commit 43db94e94f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -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 {