{"record":{"id":"587720f3a6fe4bbe","repo":"briannesbitt/Carbon","slug":"classname-has-not-the-instance-method-needed-to-587720","errorCode":null,"errorMessage":"$className has not the instance() method needed to cast the date.","messagePattern":"\\$className has not the instance\\(\\) method needed to cast the date\\.","errorType":"exception","errorClass":"InvalidCastException","httpStatus":null,"severity":"error","filePath":"src/Carbon/Traits/Cast.php","lineNumber":43,"sourceCode":"{\n    /**\n     * Cast the current instance into the given class.\n     *\n     * @template T\n     *\n     * @param class-string<T> $className The $className::instance() method will be called to cast the current object.\n     *\n     * @return T\n     */\n    public function cast(string $className): mixed\n    {\n        if (!method_exists($className, 'instance')) {\n            if (is_a($className, DateTimeInterface::class, true)) {\n                return $className::createFromFormat('U.u', $this->rawFormat('U.u'))\n                    ->setTimezone($this->getTimezone());\n            }\n\n            throw new InvalidCastException(\"$className has not the instance() method needed to cast the date.\");\n        }\n\n        return $className::instance($this);\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":49,"githubUrl":"https://github.com/briannesbitt/Carbon/blob/b13f05955dcfd7da71d60af745fd148cbdb73505/src/Carbon/Traits/Cast.php#L25-L49","documentation":"Error \"$className has not the instance() method needed to cast the date.\" thrown in briannesbitt/Carbon.","triggerScenarios":"Thrown at src/Carbon/Traits/Cast.php:43 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"}