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

ralvez's avatar

Carbon Error after system re-install

I had a issue with my Linux system and the fastest way to solve it was to re-install. Since my /home directory is in a separate partition all my data remained unchanged. However, (there is a "however" or I would not be posting ;) ) when I try to start the server (php artisan serve) I get this error: "PHP Fatal error: Type of Carbon\CarbonPeriod::EXCLUDE_START_DATE must be compatible with DatePeriod::EXCLUDE_START_DATE of type int in /home/ralvez/Code/PHP/careyalvezart/vendor/nesbot/carbon/src/Carbon/CarbonPeriod.php on line 184"

I tried: "composer require nesbot/carbon" but I just get a bunch or errors.

Any ideas on how to tackle this issues would be appreciated.

0 likes
2 replies
LaryAI's avatar

The error you’re seeing:

PHP Fatal error:  Type of Carbon\CarbonPeriod::EXCLUDE_START_DATE must be compatible with DatePeriod::EXCLUDE_START_DATE of type int in /home/ralvez/Code/PHP/careyalvezart/vendor/nesbot/carbon/src/Carbon/CarbonPeriod.php on line 184

usually happens because of a mismatch between your PHP version and the version of the nesbot/carbon package installed in your project.

Why this happens:

  • Newer versions of PHP (especially PHP 8.2+) introduced stricter type compatibility for class constants and properties.
  • If your project’s vendor directory or composer.lock references an older version of Carbon, it may not be compatible with your current PHP version.

How to fix:

  1. Delete vendor and composer.lock
    Remove your current dependencies and lock file to force Composer to resolve compatible versions.

    rm -rf vendor composer.lock
    
  2. Check your PHP version
    Make sure you know which PHP version you’re running:

    php -v
    
  3. Update Composer dependencies
    Run:

    composer install
    

    This will install the versions specified in your composer.json that are compatible with your PHP version.

  4. If you still get errors, explicitly require the latest Carbon:

    composer require nesbot/carbon
    

    This will ensure you have the latest version compatible with your PHP version.

  5. If you get a lot of errors during composer install or composer require, try updating Composer itself:

    composer self-update
    

Summary:
This is a common issue after a system re-install if your PHP version changes. The key is to clear out old dependencies and let Composer resolve new, compatible versions.

If you still have issues, please post the output of php -v and your composer.json so we can help further!

Please or to participate in this conversation.