Skip to content

Commit

Permalink
Merge pull request #2663 from driesvints/patch-1
Browse files Browse the repository at this point in the history
Fix PHP 8.2 issue with false for lastErrors
  • Loading branch information
kylekatarnls authored Sep 2, 2022
2 parents d63266f + bb7a70f commit 01bc4cd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/Carbon/Traits/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,13 +921,20 @@ public static function make($var)
/**
* Set last errors.
*
* @param array $lastErrors
* @param array|bool $lastErrors
*
* @return void
*/
private static function setLastErrors(array $lastErrors)
private static function setLastErrors($lastErrors)
{
static::$lastErrors = $lastErrors;
if (\is_array($lastErrors) || $lastErrors === false) {
static::$lastErrors = \is_array($lastErrors) ? $lastErrors : [
'warning_count' => 0,
'warnings' => [],
'error_count' => 0,
'errors' => [],
];
}
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/Carbon/LastErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public function testCreateHandlesLastErrors()
$this->assertSame($carbon->getLastErrors(), $datetime->getLastErrors());

$carbon = new Carbon('2017-02-15');
$datetime = new DateTime('2017-02-15');

$this->assertSame($this->noErrors, $carbon->getLastErrors());
$this->assertSame($carbon->getLastErrors(), $datetime->getLastErrors());
}
}
2 changes: 0 additions & 2 deletions tests/CarbonImmutable/LastErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public function testCreateHandlesLastErrors()
$this->assertSame($carbon->getLastErrors(), $datetime->getLastErrors());

$carbon = new Carbon('2017-02-15');
$datetime = new DateTime('2017-02-15');

$this->assertSame($this->noErrors, $carbon->getLastErrors());
$this->assertSame($carbon->getLastErrors(), $datetime->getLastErrors());
}
}

0 comments on commit 01bc4cd

Please sign in to comment.