briannesbitt/Carbon · error · InvalidArgumentException

$anchorDay is not compatible with overflow

Error message

$anchorDay is not compatible with overflow

What it means

Error "$anchorDay is not compatible with overflow" thrown in briannesbitt/Carbon.

Source

Thrown at src/Carbon/Traits/Date.php:2964

            if ($utcUnit) {
                $unit = static::singularUnit($utcUnit);

                return $this->{"{$action}UTCUnit"}($unit, ...$parameters);
            }

            if (preg_match('/^(Month|Quarter|Year|Decade|Century|Centurie|Millennium|Millennia)s?(No|With|Without|WithNo)Overflow$/', $unit, $match)) {
                $unit = $match[1];
                $overflow = $match[2] === 'With';
            }

            $unit = static::singularUnit($unit);
        }

        if (static::isModifiableUnit($unit)) {
            $anchorDay = $this->getMagicParameter($parameters, 1, 'anchorDay', null);

            if ($anchorDay !== null && $overflow) {
                throw new InvalidArgumentException(
                    '$anchorDay is not compatible with overflow',
                );
            }

            return $this->{"{$action}Unit"}(
                $unit,
                $this->getMagicParameter($parameters, 0, 'value', 1),
                $anchorDay === null ? $overflow : OverflowMode::AnchorDay,
                $anchorDay,
            );
        }

        return null;
    }

    private function callPeriodMethod(string $method, array $parameters): ?CarbonPeriod
    {
        if (str_ends_with($method, 'Until')) {

View on GitHub (pinned to b13f05955d)

When it happens

Trigger: Thrown at src/Carbon/Traits/Date.php:2964 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of briannesbitt/Carbon@b13f05955d (2026-08-17). Data as JSON: /api/errors/e0aff639947687ba. Report an issue: GitHub.