briannesbitt/Carbon · error · InvalidArgumentException

Macro '$methodName' not found

Error message

Macro '$methodName' not found

What it means

Error "Macro '$methodName' not found" thrown in briannesbitt/Carbon.

Source

Thrown at src/Carbon/PHPStan/MacroExtension.php:85

            $classReflection->getName() !== CarbonInterface::class &&
            !$classReflection->isSubclassOf(CarbonInterface::class)
        ) {
            return false;
        }

        $className = $classReflection->getName();

        return \is_callable([$className, 'hasMacro']) &&
            $className::hasMacro($methodName);
    }

    /**
     * {@inheritdoc}
     */
    public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
    {
        $macros = FactoryImmutable::getDefaultInstance()->getSettings()['macros'] ?? [];
        $macro = $macros[$methodName] ?? throw new InvalidArgumentException("Macro '$methodName' not found");
        $static = false;
        $final = false;
        $deprecated = false;
        $docComment = null;

        if (\is_array($macro) && \count($macro) === 2 && \is_string($macro[1])) {
            \assert($macro[1] !== '');

            $reflection = new ReflectionMethod($macro[0], $macro[1]);
            $closure = \is_object($macro[0]) ? $reflection->getClosure($macro[0]) : $reflection->getClosure();

            $static = $reflection->isStatic();
            $final = $reflection->isFinal();
            $deprecated = $reflection->isDeprecated();
            $docComment = $reflection->getDocComment() ?: null;
        } elseif (\is_string($macro)) {
            $reflection = new ReflectionFunction($macro);
            $closure = $reflection->getClosure();

View on GitHub (pinned to b13f05955d)

When it happens

Trigger: Thrown at src/Carbon/PHPStan/MacroExtension.php:85 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/83dd0da9ee85b901. Report an issue: GitHub.