Carbon Comparison Error with PHP 8.1
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:
- We updated Laravel to support PHP 8.1
- This in turn updated Carbon to a newer version.
- Carbon recently made a significant change in a minor version.
- This broke our tests.
Here is the relevant PR: https://github.com/briannesbitt/Carbon/pull/2530
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.