Carbon Comparison Error with PHP 8.1

Posted on Aug 31, 2022

Recently we tried to upgrade an application to PHP 8.1 and we ran into strange errors. A number of tests were failing and all the failures were related to Carbon dates.

Here’s what happened:

  1. We updated Laravel to support PHP 8.1
  2. This in turn updated Carbon to a newer version.
  3. Carbon recently made a significant change in a minor version.
  4. This broke our tests.

Here is the relevant PR:

What’s happening?

Carbon now uses a more accurate way of comparing dates. This is good. But if you have broken code, it means your were being a little sloppy somewhere. From now on, if you compare dates, you’ll compare down to the millisecond.

comments powered by Disqus