ramsey/uuid · error · UnsupportedOperationException
The provided factory does not support the uuid7() method
Error message
The provided factory does not support the uuid7() method
What it means
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.
Source
Thrown at src/Uuid.php:695
/**
* Returns a version 7 (Unix Epoch time) UUID
*
* @param DateTimeInterface | null $dateTime An optional date/time from which to create the version 7 UUID. If not
* provided, the UUID is generated using the current date/time.
*
* @return UuidInterface A UuidInterface instance that represents a version 7 UUID
*/
public static function uuid7(?DateTimeInterface $dateTime = null): UuidInterface
{
$factory = self::getFactory();
if (method_exists($factory, 'uuid7')) {
/** @var UuidInterface */
return $factory->uuid7($dateTime);
}
throw new UnsupportedOperationException('The provided factory does not support the uuid7() method');
}
/**
* Returns a version 8 (custom format) UUID
*
* The bytes provided may contain any value according to your application's needs. Be aware, however, that other
* applications may not understand the semantics of the value.
*
* @param string $bytes A 16-byte octet string. This is an open blob of data that you may fill with 128 bits of
* information. Be aware, however, bits 48 through 51 will be replaced with the UUID version field, and bits 64
* and 65 will be replaced with the UUID variant. You MUST NOT rely on these bits for your application needs.
*
* @return UuidInterface A UuidInterface instance that represents a version 8 UUID
*
* @pure
*/
public static function uuid8(string $bytes): UuidInterface
{View on GitHub (pinned to da5b521600)
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()
Example fix
// before: custom factory written pre-v7
Uuid::setFactory($legacyFactory);
$uuid = Uuid::uuid7();
// UnsupportedOperationException: The provided factory does not support the uuid7() method
// after: extend the default factory
final class ApplicationUuidFactory extends UuidFactory {}
Uuid::setFactory(new ApplicationUuidFactory());
$uuid = Uuid::uuid7(); // works, inherited from UuidFactory Defensive patterns
Strategy: type-guard
Validate before calling
// Run before calling Uuid::uuid7()
if (!method_exists(Uuid::getFactory(), 'uuid7')) {
throw new \RuntimeException('Registered UUID factory does not support uuid7()');
} Type guard
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;
function factorySupportsUuid7(): bool
{
return Uuid::getFactory() instanceof UuidFactory
|| method_exists(Uuid::getFactory(), 'uuid7');
} Try / catch
use Ramsey\Uuid\Exception\UnsupportedOperationException;
try {
$uuid = Uuid::uuid7($dateTime);
} catch (UnsupportedOperationException $e) {
$uuid = Uuid::uuid4(); // degrade to v4 only if acceptable for your ordering needs
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- The provided factory does not support the uuid8() method
- The method fromHexadecimal() does not exist on the provided
- Fields used to create a UuidV7 must represent a version 7 (U
- Fields used to create a UuidV2 must represent a version 2 (D
- Fields used to create a UuidV3 must represent a version 3 (n
AI-assisted analysis of ramsey/uuid@da5b521600 (2026-08-21).
Data as JSON: /api/errors/8410ef6befddf657.
Report an issue: GitHub.