12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- .. _nonstandard.other:
- =======================
- Other Nonstandard UUIDs
- =======================
- Sometimes, you might encounter a string that looks like a UUID but doesn't
- follow the `RFC 4122`_ specification. Take this string, for example:
- .. code-block:: text
- d95959bc-2ff5-43eb-fccd-14883ba8f174
- At a glance, this looks like a valid UUID, but the variant bits don't match RFC
- 4122. Instead of throwing a validation exception, ramsey/uuid will assume this
- is a UUID, since it fits the format and has 128 bits, but it will represent it
- as a :php:class:`Ramsey\\Uuid\\Nonstandard\\Uuid`.
- .. code-block:: php
- :caption: Create an instance of Nonstandard\\Uuid from a non-RFC 4122 UUID
- use Ramsey\Uuid\Uuid;
- $uuid = Uuid::fromString('d95959bc-2ff5-43eb-fccd-14883ba8f174');
- printf(
- "Class: %s\nUUID: %s\nVersion: %d\nVariant: %s\n",
- get_class($uuid),
- $uuid->toString(),
- $uuid->getFields()->getVersion(),
- $uuid->getFields()->getVariant()
- );
- This will create a Nonstandard\\Uuid from the given string and print out a few
- details about it. It will look something like this:
- .. code-block:: text
- Class: Ramsey\Uuid\Nonstandard\Uuid
- UUID: d95959bc-2ff5-43eb-fccd-14883ba8f174
- Version: 0
- Variant: 7
- Note that the version is 0. Since the variant is 7, and there is no
- formal specification for this variant of UUID, ramsey/uuid has no way of knowing
- what type of UUID this is.
- .. _RFC 4122: https://tools.ietf.org/html/rfc4122
|