{"record":{"id":"ef5a370343acf536","repo":"ramsey/uuid","slug":"the-provided-factory-does-not-support-the-uuid8","errorCode":null,"errorMessage":"The provided factory does not support the uuid8() method","messagePattern":"The provided factory does not support the uuid8\\(\\) method","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/Uuid.php","lineNumber":725,"sourceCode":"     *\n     * @return UuidInterface A UuidInterface instance that represents a version 8 UUID\n     *\n     * @pure\n     */\n    public static function uuid8(string $bytes): UuidInterface\n    {\n        /** @phpstan-ignore possiblyImpure.methodCall */\n        $factory = self::getFactory();\n\n        if (method_exists($factory, 'uuid8')) {\n            /**\n             * @var UuidInterface\n             * @phpstan-ignore possiblyImpure.methodCall\n             */\n            return $factory->uuid8($bytes);\n        }\n\n        throw new UnsupportedOperationException('The provided factory does not support the uuid8() method');\n    }\n}\n","sourceCodeStart":707,"sourceCodeEnd":728,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Uuid.php#L707-L728","documentation":"Uuid::uuid8() delegates to the globally registered factory, but uuid8() is an optional capability beyond UuidFactoryInterface — the default Ramsey\\Uuid\\UuidFactory implements it (custom-format v8 UUIDs shipped with version 4.7 of the library). If the registered factory has no uuid8() method, the method_exists() check fails and Ramsey\\Uuid\\Exception\\UnsupportedOperationException is thrown. This guards against custom or mock factories that predate or omit v8 support.","triggerScenarios":"Calling Uuid::setFactory($factory) with a factory implementing only UuidFactoryInterface, a decorator that does not forward uuid8(), or a PHPUnit mock without the method — then calling Uuid::uuid8($bytes) with the 16-byte custom blob.","commonSituations":"Introducing v8 custom-format UUIDs in apps with an existing custom factory; mocks/doubles built before the method existed; wrapper factories in DI containers forwarding only the interface methods; library upgrades where bindings still construct old wrappers.","solutions":["Extend Ramsey\\Uuid\\UuidFactory with the custom factory — uuid8() comes along for free","Add uuid8(string $bytes): UuidInterface to the custom factory and delegate to an inner UuidFactory when wrapping one","Refresh test mocks/doubles so they stub uuid8()","Guard call sites: if (!method_exists(Uuid::getFactory(), 'uuid8')) construct via Uuid::fromBytes($bytes) with the v8 bits set manually"],"exampleFix":"// before: decorator factory forwards only interface methods\nUuid::setFactory(new TimingDecoratorFactory($innerFactory)); // no uuid8()\n$uuid = Uuid::uuid8($bytes);\n// UnsupportedOperationException: The provided factory does not support the uuid8() method\n\n// after: extend UuidFactory (or forward the method) and keep v8 support\nfinal class TimingDecoratorFactory extends UuidFactory\n{\n    public function uuid8(string $bytes): UuidInterface\n    {\n        return parent::uuid8($bytes);\n    }\n}\nUuid::setFactory(new TimingDecoratorFactory());\n$uuid = Uuid::uuid8($bytes);","handlingStrategy":"type-guard","validationCode":"// Run before calling Uuid::uuid8()\nif (!method_exists(Uuid::getFactory(), 'uuid8')) {\n    throw new \\RuntimeException('Registered UUID factory does not support uuid8()');\n}","typeGuard":"use Ramsey\\Uuid\\Uuid;\nuse Ramsey\\Uuid\\UuidFactory;\n\nfunction factorySupportsUuid8(): bool\n{\n    return Uuid::getFactory() instanceof UuidFactory\n        || method_exists(Uuid::getFactory(), 'uuid8');\n}","tryCatchPattern":"use Ramsey\\Uuid\\Exception\\UnsupportedOperationException;\n\ntry {\n    $uuid = Uuid::uuid8($bytes);\n} catch (UnsupportedOperationException $e) {\n    // custom-layout path unavailable on this factory\n    throw new \\RuntimeException('Enable a factory with uuid8() support', 0, $e);\n}","preventionTips":["Extend Ramsey\\Uuid\\UuidFactory with custom factories so uuid8() is inherited","Forward uuid8() explicitly in decorator/wrapper factories","Add uuid8() to factory mocks when testing custom-format paths","Prefer Uuid::fromBytes() with manually set v8 bits if factory support is uncertain"],"tags":["php","ramsey-uuid","uuid","uuidv8","factory","unsupported-operation","custom-factory"],"backgroundTag":"factory-method-unsupported","analyzedSha":"da5b521600a707d2dd097598464bd3090de850f5","analyzedAt":"2026-08-21T01:35:29.252Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}