Version 3: Name-based (MD5)¶
RFC 4122 states, “If backward compatibility is not an issue, SHA-1 is preferred.” As a result, the use of version 5 UUIDs is preferred over version 3 UUIDs, unless you have a specific use-case for version 3 UUIDs.
To learn about name-based UUIDs, read the section Version 5: Name-based (SHA-1). Version 3 UUIDs behave exactly the same as version 5 UUIDs. The only difference is the hashing algorithm used to generate the UUID.
Version 3 UUIDs use MD5 as the hashing algorithm for combining the namespace and the name.
Due to the use of a different hashing algorithm, version 3 UUIDs generated with any given namespace and name will differ from version 5 UUIDs generated using the same namespace and name.
As an example, let’s take a look at generating a version 3 UUID using the same namespace and name used in “Generate a version 5, name-based UUID for a URL.”
use Ramsey\Uuid\Uuid; $uuid = Uuid::uuid3(Uuid::NAMESPACE_URL, 'https://www.php.net');
Even though the namespace and name are the same, the version 3 UUID generated
will always be
Likewise, we can use the custom namespace we created in “Generate a custom namespace UUID” to generate a version 3 UUID, but the result will be different from the version 5 UUID with the same custom namespace and name.
use Ramsey\Uuid\Uuid; const WIDGET_NAMESPACE = '4bdbe8ec-5cb5-11ea-bc55-0242ac130003'; $uuid = Uuid::uuid3(WIDGET_NAMESPACE, 'widget/1234567890');
With this custom namespace, the version 3 UUID for the name “widget/1234567890”
will always be
Version 3 UUIDs generated in ramsey/uuid are instances of UuidV3. Check out
Ramsey\Uuid\Rfc4122\UuidV3 API documentation to learn
more about what you can do with a UuidV3 instance.