{"record":{"id":"8b9f73e1a08cfe0f","repo":"briannesbitt/Carbon","slug":"anchorday-parameter-must-not-be-set-for-mode-ove","errorCode":null,"errorMessage":"$anchorDay parameter must not be set for $mode OverflowMode::{$mode->name}","messagePattern":"\\$anchorDay parameter must not be set for \\$mode OverflowMode::(.+?)","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Carbon/CarbonPeriod.php","lineNumber":576,"sourceCode":"     */\n    protected static function addMissingParts(string $source, string $target): string\n    {\n        $pattern = '/'.preg_replace('/\\d+/', '[0-9]+', preg_quote($target, '/')).'$/';\n\n        $result = preg_replace($pattern, $target, $source, 1, $count);\n\n        return $count ? $result : $target;\n    }\n\n    private static function getStartAndEndForCyclePeriod(\n        DateTimeInterface|string|int|null $start = null,\n        DateTimeInterface|string|int|null $end = null,\n        ?int $recurrences = null,\n        ?int $anchorDay = null,\n        OverflowMode $mode = OverflowMode::AnchorDay,\n    ): array {\n        if ($anchorDay !== null && $mode !== OverflowMode::AnchorDay) {\n            throw new InvalidArgumentException(\n                '$anchorDay parameter must not be set for $mode OverflowMode::'.$mode->name,\n            );\n        }\n\n        if ($end !== null && $recurrences !== null) {\n            throw new InvalidArgumentException(\n                'You must specify $end or $recurrences but not both',\n            );\n        }\n\n        if (\\is_int($start)) {\n            $start = CarbonImmutable::createFromTimestamp($start);\n        } elseif (\\is_string($start)) {\n            $start = CarbonImmutable::parse($start);\n        }\n\n        $start ??= CarbonImmutable::now();\n","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/briannesbitt/Carbon/blob/b13f05955dcfd7da71d60af745fd148cbdb73505/src/Carbon/CarbonPeriod.php#L558-L594","documentation":"CarbonPeriod::monthly()/quarterly()/yearly() accept an $anchorDay (day of month to pin, e.g. 'the 31st') together with an OverflowMode controlling what happens when a month has fewer days. An anchor day only has meaning with the default OverflowMode::AnchorDay; the NoOverflow and Overflow modes define their own day handling, so passing a non-null $anchorDay alongside them is contradictory and rejected in getStartAndEndForCyclePeriod() (src/Carbon/CarbonPeriod.php:576).","triggerScenarios":"CarbonPeriod::monthly($start, $end, null, 31, OverflowMode::NoOverflow); the same with OverflowMode::Overflow — any cycle-constructor call where the 4th argument is non-null while $mode is not OverflowMode::AnchorDay.","commonSituations":"Refactoring a monthly/quarterly/yearly billing or reminder schedule and carrying the anchor-day argument over while switching the overflow strategy; positional-argument mistakes where a value meant for $recurrences lands in $anchorDay.","solutions":["Drop the anchor day (pass null) when using NoOverflow or Overflow modes","Keep the anchor day and stay on the default mode (omit $mode, i.e. OverflowMode::AnchorDay)","Use named arguments to remove positional mix-ups: CarbonPeriod::monthly(start: $start, end: $end, mode: OverflowMode::NoOverflow)"],"exampleFix":"// before\n$period = CarbonPeriod::monthly('2021-01-31', '2021-12-31', null, 31, OverflowMode::NoOverflow);\n\n// after — anchor day only with AnchorDay mode\n$period = CarbonPeriod::monthly('2021-01-31', '2021-12-31', null, 31);\n// or keep the mode and drop the anchor\n$period = CarbonPeriod::monthly('2021-01-31', '2021-12-31', null, null, OverflowMode::NoOverflow);","handlingStrategy":"validation","validationCode":"if ($anchorDay !== null && $mode !== \\Carbon\\Enums\\OverflowMode::AnchorDay) {\n    throw new InvalidArgumentException(\n        'anchorDay may only be combined with OverflowMode::AnchorDay'\n    );\n}\n$period = CarbonPeriod::monthly($start, $end, $recurrences, $anchorDay, $mode);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use named arguments for monthly()/quarterly()/yearly() so $recurrences, $anchorDay and $mode cannot shift positions","Keep a single source of truth for schedule config; forbid configs that set both anchor_day and overflow mode"],"tags":["carbon","carbon-period","argument-combination","date-overflow","billing-cycle"],"backgroundTag":"invalid-argument-combination","analyzedSha":"b13f05955dcfd7da71d60af745fd148cbdb73505","analyzedAt":"2026-08-17T04:40:56.953Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}