{"record":{"id":"3d6d148c4c25d235","repo":"ramsey/uuid","slug":"the-method-fromhexadecimal-does-not-exist-on-the","errorCode":null,"errorMessage":"The method fromHexadecimal() does not exist on the provided factory","messagePattern":"The method fromHexadecimal\\(\\) does not exist on the provided factory","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"src/Uuid.php","lineNumber":545,"sourceCode":"     * @throws InvalidArgumentException\n     *\n     * @pure\n     */\n    public static function fromHexadecimal(Hexadecimal $hex): UuidInterface\n    {\n        /** @phpstan-ignore possiblyImpure.methodCall */\n        $factory = self::getFactory();\n\n        if (method_exists($factory, 'fromHexadecimal')) {\n            /** @phpstan-ignore possiblyImpure.methodCall */\n            $uuid = $factory->fromHexadecimal($hex);\n            /** @phpstan-ignore possiblyImpure.functionCall */\n            assert($uuid instanceof UuidInterface);\n\n            return $uuid;\n        }\n\n        throw new BadMethodCallException('The method fromHexadecimal() does not exist on the provided factory');\n    }\n\n    /**\n     * Creates a UUID from a 128-bit integer string\n     *\n     * @param string $integer String representation of 128-bit integer\n     *\n     * @return UuidInterface A UuidInterface instance created from the string representation of a 128-bit integer\n     *\n     * @throws InvalidArgumentException\n     *\n     * @pure\n     */\n    public static function fromInteger(string $integer): UuidInterface\n    {\n        /** @phpstan-ignore possiblyImpure.methodCall */\n        return self::getFactory()->fromInteger($integer);\n    }","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Uuid.php#L527-L563","documentation":"Uuid::fromHexadecimal() delegates to the globally registered factory (set via Uuid::setFactory()). The method is an extra capability beyond UuidFactoryInterface — only the default Ramsey\\Uuid\\UuidFactory (and subclasses) implement it. When the registered factory lacks fromHexadecimal(), the method_exists() capability check fails and a SPL BadMethodCallException is thrown. This is a guard for custom/test factories, not a flaw in normal usage.","triggerScenarios":"Calling Uuid::setFactory($factory) with a factory that only implements UuidFactoryInterface (or a PHPUnit mock/anonymous class without fromHexadecimal()), then calling Uuid::fromHexadecimal(new Hexadecimal('...')). The default factory never triggers this.","commonSituations":"DI containers binding a minimal custom factory; PHPUnit test doubles mocking UuidFactoryInterface; wrapper/decorator factories written from scratch instead of extending UuidFactory; static factories in legacy code predating the method.","solutions":["Extend Ramsey\\Uuid\\UuidFactory with the custom factory instead of implementing UuidFactoryInterface — fromHexadecimal() is inherited","Add fromHexadecimal(Hexadecimal $hex): UuidInterface to the custom factory, delegating to an inner UuidFactory if wrapping one","Update test mocks/doubles to include the method","Guard the call site with method_exists(Uuid::getFactory(), 'fromHexadecimal') and choose an alternative construction path"],"exampleFix":"// before: minimal factory implementing only the interface\nUuid::setFactory(new class implements UuidFactoryInterface { /* ... */ });\n$uuid = Uuid::fromHexadecimal($hex);\n// BadMethodCallException: The method fromHexadecimal() does not exist on the provided factory\n\n// after: extend the default factory, which has the method\nUuid::setFactory(new class extends UuidFactory {\n    // custom behavior here; fromHexadecimal() inherited\n});\n$uuid = Uuid::fromHexadecimal($hex);","handlingStrategy":"type-guard","validationCode":"// Run before calling Uuid::fromHexadecimal()\nif (!method_exists(Uuid::getFactory(), 'fromHexadecimal')) {\n    // registered factory lacks the capability; use a supported path\n    throw new \\RuntimeException('Registered UUID factory does not support fromHexadecimal()');\n}","typeGuard":"use Ramsey\\Uuid\\Uuid;\nuse Ramsey\\Uuid\\UuidFactory;\n\nfunction factorySupportsFromHexadecimal(): bool\n{\n    return Uuid::getFactory() instanceof UuidFactory\n        || method_exists(Uuid::getFactory(), 'fromHexadecimal');\n}","tryCatchPattern":"try {\n    $uuid = Uuid::fromHexadecimal($hex);\n} catch (\\BadMethodCallException $e) {\n    // factory lacks the method: fix the factory registration\n    throw new \\RuntimeException('Replace the custom UUID factory or extend UuidFactory', 0, $e);\n}","preventionTips":["Extend Ramsey\\Uuid\\UuidFactory rather than implementing UuidFactoryInterface from scratch","When wrapping/decorating factories, forward every public method, not just interface methods","Update test mocks whenever new factory methods are adopted","Check method_exists() before optional-capability calls"],"tags":["php","ramsey-uuid","uuid","factory","bad-method-call","custom-factory"],"backgroundTag":"factory-method-unsupported","analyzedSha":"da5b521600a707d2dd097598464bd3090de850f5","analyzedAt":"2026-08-21T01:35:29.252Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}