{"record":{"id":"d341beaf908997b2","repo":"briannesbitt/Carbon","slug":"unit-cannot-be-changed-to-float-value-value-int","errorCode":null,"errorMessage":"$unit cannot be changed to float value $value, integer expected","messagePattern":"\\$unit cannot be changed to float value \\$value, integer expected","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Carbon/Traits/Date.php","lineNumber":2537,"sourceCode":"     * @param string                 $unit      year, month, day, hour, minute, second or microsecond\n     * @param Month|int|float|null   $value     new value for given unit\n     * @param OverflowMode|bool|null $overflow  either overflow (when the day does not exist in current month)\n     *                                          is allowed or not, or should use an anchor day\n     * @param ?int                   $anchorDay the day to which to go after setting year/quarter/month,\n     *                                          if given but it does not exist in current month, it will\n     *                                          go to the last day of the month\n     */\n    public function setUnit(\n        string $unit,\n        Month|int|float|null $value = null,\n        OverflowMode|bool|null $overflow = null,\n        ?int $anchorDay = null,\n    ): static {\n        if (\\is_float($value)) {\n            $int = (int) $value;\n\n            if ((float) $int !== $value) {\n                throw new InvalidArgumentException(\n                    \"$unit cannot be changed to float value $value, integer expected\",\n                );\n            }\n\n            $value = $int;\n        }\n\n        $overflow = $this->getOverflowMode($overflow, $anchorDay);\n        $unit = static::singularUnit($unit);\n        $value = self::monthToInt($value, $unit);\n        $dateUnits = ['year', 'month', 'day'];\n\n        if (\\in_array($unit, $dateUnits)) {\n            if ($unit !== 'day') {\n                $overflow ??= $this->shouldUnitOverflow($unit)\n                    ? OverflowMode::Overflow\n                    : OverflowMode::NoOverflow;\n                $anchorDay = match ($overflow) {","sourceCodeStart":2519,"sourceCodeEnd":2555,"githubUrl":"https://github.com/briannesbitt/Carbon/blob/b13f05955dcfd7da71d60af745fd148cbdb73505/src/Carbon/Traits/Date.php#L2519-L2555","documentation":"Error \"$unit cannot be changed to float value $value, integer expected\" thrown in briannesbitt/Carbon.","triggerScenarios":"Thrown at src/Carbon/Traits/Date.php:2537 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b13f05955dcfd7da71d60af745fd148cbdb73505","analyzedAt":"2026-08-17T04:40:56.953Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}