other.rst 1.5 KB

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