{"record":{"id":"a408879034ebd5ce","repo":"briannesbitt/Carbon","slug":"method-method-does-not-exist","errorCode":null,"errorMessage":"Method $method does not exist.","messagePattern":"Method \\$method does not exist\\.","errorType":"exception","errorClass":"UnknownMethodException","httpStatus":null,"severity":"error","filePath":"src/Carbon/CarbonPeriod.php","lineNumber":1900,"sourceCode":"            case 'hour':\n            case 'minutes':\n            case 'minute':\n            case 'seconds':\n            case 'second':\n            case 'milliseconds':\n            case 'millisecond':\n            case 'microseconds':\n            case 'microsecond':\n                return $this->setDateInterval((\n                    // Override default P1D when instantiating via fluent setters.\n                    [$this->isDefaultInterval ? new CarbonInterval('PT0S') : $this->dateInterval, $method]\n                )(...$parameters));\n        }\n\n        $dateClass = $this->dateClass;\n\n        if ($this->localStrictModeEnabled ?? $dateClass::isStrictModeEnabled()) {\n            throw new UnknownMethodException($method);\n        }\n\n        return $this;\n    }\n\n    /**\n     * Set the instance's timezone from a string or object and apply it to start/end.\n     */\n    public function setTimezone(DateTimeZone|string|int $timezone): static\n    {\n        $self = $this->copyIfImmutable();\n        $self->timezoneSetting = $timezone;\n        $self->timezone = CarbonTimeZone::instance($timezone);\n\n        if ($self->startDate) {\n            $self = $self->setStartDate($self->startDate->setTimezone($timezone));\n        }\n","sourceCodeStart":1882,"sourceCodeEnd":1918,"githubUrl":"https://github.com/briannesbitt/Carbon/blob/b13f05955dcfd7da71d60af745fd148cbdb73505/src/Carbon/CarbonPeriod.php#L1882-L1918","documentation":"CarbonPeriod::__call() maps fluent unit names ('days', 'hours', 'month', singulars, etc.) to interval setters and forwards registered macros. For anything unrecognized, behavior depends on strict mode (per-period ->setStrictMode() or the date class global setting): strict mode throws UnknownMethodException ('Method X does not exist.'), non-strict mode silently returns $this and swallows the typo (src/Carbon/CarbonPeriod.php:1900).","triggerScenarios":"Typos in fluent chains: ->startdDate('...') or ->setDateIntervall('P1D'); calling date methods on the period (->addDay()); calling a macro name that was never registered with CarbonPeriod::macro() — all while strict mode is enabled (the default).","commonSituations":"Long fluent builder chains where one segment is misspelled and fails only at runtime; upgrading code that relied on non-strict silent no-ops; macros renamed or moved between package versions.","solutions":["Fix the method name — check the real API: setStartDate(), setEndDate(), setDateInterval(), setRecurrences(), filter(), excludeStartDate()","Register the macro before use: CarbonPeriod::macro('myMethod', fn (...) => ...)","Verify dynamically: method_exists($period, $name) || CarbonPeriod::hasMacro($name)"],"exampleFix":"// before\n$period = CarbonPeriod::create()->startdDate('2021-01-01'); // typo\n\n// after\n$period = CarbonPeriod::create()->setStartDate('2021-01-01');","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function periodSupports(CarbonPeriod $period, string $method): bool\n{\n    return method_exists($period, $method) || CarbonPeriod::hasMacro($method);\n}\n\nif (!periodSupports($period, $name)) {\n    throw new BadMethodCallException(\"CarbonPeriod has no method '$name'\");\n}\n$period->{$name}(...$args);","tryCatchPattern":"try {\n    $result = $period->{$dynamicName}();\n} catch (\\Carbon\\Exceptions\\UnknownMethodException $e) {\n    // log the typo'd/misrouted call with the method name from $e->getMethod()\n    throw $e;\n}","preventionTips":["Keep strict mode on (default) so typos fail loudly instead of returning $this silently","Register macros at bootstrap, not lazily, and verify with CarbonPeriod::hasMacro()","Add static analysis (PHPStan) to catch misspelled fluent calls before runtime"],"tags":["carbon","carbon-period","magic-methods","typo","strict-mode"],"backgroundTag":"undefined-method-call","analyzedSha":"b13f05955dcfd7da71d60af745fd148cbdb73505","analyzedAt":"2026-08-17T04:40:56.953Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}