diff --git a/src/Carbon/Traits/Creator.php b/src/Carbon/Traits/Creator.php index c28fc368ea..be2c0f7c27 100644 --- a/src/Carbon/Traits/Creator.php +++ b/src/Carbon/Traits/Creator.php @@ -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' => [], + ]; + } } /** diff --git a/tests/Carbon/LastErrorTest.php b/tests/Carbon/LastErrorTest.php index a8ab2b253b..0de848ae1e 100644 --- a/tests/Carbon/LastErrorTest.php +++ b/tests/Carbon/LastErrorTest.php @@ -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()); } } diff --git a/tests/CarbonImmutable/LastErrorTest.php b/tests/CarbonImmutable/LastErrorTest.php index b075b062d2..6207740c3e 100644 --- a/tests/CarbonImmutable/LastErrorTest.php +++ b/tests/CarbonImmutable/LastErrorTest.php @@ -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()); } }