{"record":{"id":"8410ef6befddf657","repo":"ramsey/uuid","slug":"the-provided-factory-does-not-support-the-uuid7","errorCode":null,"errorMessage":"The provided factory does not support the uuid7() method","messagePattern":"The provided factory does not support the uuid7\\(\\) method","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/Uuid.php","lineNumber":695,"sourceCode":"\n    /**\n     * Returns a version 7 (Unix Epoch time) UUID\n     *\n     * @param DateTimeInterface | null $dateTime An optional date/time from which to create the version 7 UUID. If not\n     *     provided, the UUID is generated using the current date/time.\n     *\n     * @return UuidInterface A UuidInterface instance that represents a version 7 UUID\n     */\n    public static function uuid7(?DateTimeInterface $dateTime = null): UuidInterface\n    {\n        $factory = self::getFactory();\n\n        if (method_exists($factory, 'uuid7')) {\n            /** @var UuidInterface */\n            return $factory->uuid7($dateTime);\n        }\n\n        throw new UnsupportedOperationException('The provided factory does not support the uuid7() method');\n    }\n\n    /**\n     * Returns a version 8 (custom format) UUID\n     *\n     * The bytes provided may contain any value according to your application's needs. Be aware, however, that other\n     * applications may not understand the semantics of the value.\n     *\n     * @param string $bytes A 16-byte octet string. This is an open blob of data that you may fill with 128 bits of\n     *     information. Be aware, however, bits 48 through 51 will be replaced with the UUID version field, and bits 64\n     *     and 65 will be replaced with the UUID variant. You MUST NOT rely on these bits for your application needs.\n     *\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    {","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Uuid.php#L677-L713","documentation":"Uuid::uuid7() delegates to the globally registered factory, but uuid7() is not part of UuidFactoryInterface — it is a capability of the default Ramsey\\Uuid\\UuidFactory (version 7 UUIDs were added in ramsey/uuid 4.7). When the registered factory lacks a uuid7() method, the method_exists() check fails and Ramsey\\Uuid\\Exception\\UnsupportedOperationException is thrown. Custom or mock factories written against older versions are the usual culprits.","triggerScenarios":"Calling Uuid::setFactory($factory) where $factory implements only UuidFactoryInterface or was written before uuid7() existed (mocks, decorators, minimal custom factories), then calling Uuid::uuid7() or Uuid::uuid7($dateTime).","commonSituations":"Adopting v7 UUIDs in an application that already registers a custom factory; PHPUnit mocks of the factory created without uuid7(); decorator factories wrapping an inner factory without forwarding new methods; upgrading ramsey/uuid while DI bindings still construct an old wrapper.","solutions":["Make the custom factory extend Ramsey\\Uuid\\UuidFactory so uuid7() is inherited","Add uuid7(?DateTimeInterface $dateTime = null): UuidInterface to the custom factory and implement or delegate it","Update test doubles to stub uuid7()","Guard call sites: if (!method_exists(Uuid::getFactory(), 'uuid7')) fall back to Uuid::uuid4()"],"exampleFix":"// before: custom factory written pre-v7\nUuid::setFactory($legacyFactory);\n$uuid = Uuid::uuid7();\n// UnsupportedOperationException: The provided factory does not support the uuid7() method\n\n// after: extend the default factory\nfinal class ApplicationUuidFactory extends UuidFactory {}\nUuid::setFactory(new ApplicationUuidFactory());\n$uuid = Uuid::uuid7(); // works, inherited from UuidFactory","handlingStrategy":"type-guard","validationCode":"// Run before calling Uuid::uuid7()\nif (!method_exists(Uuid::getFactory(), 'uuid7')) {\n    throw new \\RuntimeException('Registered UUID factory does not support uuid7()');\n}","typeGuard":"use Ramsey\\Uuid\\Uuid;\nuse Ramsey\\Uuid\\UuidFactory;\n\nfunction factorySupportsUuid7(): bool\n{\n    return Uuid::getFactory() instanceof UuidFactory\n        || method_exists(Uuid::getFactory(), 'uuid7');\n}","tryCatchPattern":"use Ramsey\\Uuid\\Exception\\UnsupportedOperationException;\n\ntry {\n    $uuid = Uuid::uuid7($dateTime);\n} catch (UnsupportedOperationException $e) {\n    $uuid = Uuid::uuid4(); // degrade to v4 only if acceptable for your ordering needs\n}","preventionTips":["Extend Ramsey\\Uuid\\UuidFactory with custom factories so uuid7() is inherited","Forward new methods in decorator factories","Stub uuid7() on test doubles once you adopt v7","Gate v7 usage behind a capability check during gradual migrations"],"tags":["php","ramsey-uuid","uuid","uuidv7","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"}