briannesbitt/Carbon · error · InvalidCastException

$className has not the instance() method needed to cast the

Error message

$className has not the instance() method needed to cast the date.

What it means

Error "$className has not the instance() method needed to cast the date." thrown in briannesbitt/Carbon.

Source

Thrown at src/Carbon/Traits/Cast.php:43

{
    /**
     * Cast the current instance into the given class.
     *
     * @template T
     *
     * @param class-string<T> $className The $className::instance() method will be called to cast the current object.
     *
     * @return T
     */
    public function cast(string $className): mixed
    {
        if (!method_exists($className, 'instance')) {
            if (is_a($className, DateTimeInterface::class, true)) {
                return $className::createFromFormat('U.u', $this->rawFormat('U.u'))
                    ->setTimezone($this->getTimezone());
            }

            throw new InvalidCastException("$className has not the instance() method needed to cast the date.");
        }

        return $className::instance($this);
    }
}

View on GitHub (pinned to b13f05955d)

When it happens

Trigger: Thrown at src/Carbon/Traits/Cast.php:43 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/587720f3a6fe4bbe. Report an issue: GitHub.