Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davy_yg's avatar

Carbon Error

I get the following error:

TypeError Carbon\Carbon::setLastErrors(): Argument #1 ($lastErrors) must be of type array, bool given, called in /home/advancew/fashionblinds.zeta-web-studio.com/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php on line 98

Any idea why?

0 likes
2 replies
LaryAI's avatar
Level 58

The error you're seeing:

TypeError
Carbon\Carbon::setLastErrors(): Argument #1 ($lastErrors) must be of type array, bool given

usually happens when Carbon tries to parse a date/time string, but the input is invalid or false, and then it passes this invalid value to a function expecting an array.

Common causes:

  • Passing false, null, or an invalid date string to Carbon's parse(), createFromFormat(), or similar methods.
  • Getting a false value from a database or another function and passing it directly to Carbon.

How to fix:

  1. Check your input: Make sure the value you're passing to Carbon is a valid date string.
  2. Add validation: Before parsing, check if the value is not false or null.

Example:

$dateString = getSomeDate(); // This might return false or an invalid date

if ($dateString && strtotime($dateString)) {
    $carbonDate = Carbon\Carbon::parse($dateString);
} else {
    // Handle the error or set a default date
    $carbonDate = null;
}

If you're using createFromFormat:

$dateString = getSomeDate();

$carbonDate = Carbon\Carbon::createFromFormat('Y-m-d', $dateString);

if ($carbonDate === false) {
    // Handle the error
}

Summary:
Check the value you're passing to Carbon. Ensure it's a valid date string and not false or null. This will prevent the TypeError you're seeing.

Please or to participate in this conversation.