A UUID is 128 bits. The library keeps it as a 16-byte string internally and exposes that form, so you can store 16 bytes instead of 36 characters.
To binary and hex
use Webpatser\Uuid\Uuid; $uuid = Uuid::v7(); $binary = $uuid->bytes; // 16 raw bytes$hex = $uuid->hex; // 32 hex characters, no hyphens$string = $uuid->string; // 36 characters strlen($binary); // 16
Binary versus string size
The demo generates 1000 UUIDs with Uuid::v4() and adds up strlen() of the string form and of the binary form: 36,000 bytes against 16,000 bytes. The timings are measured on this server.
Uuid::v4(), measured on this server just nowString, $uuid->string
read in 0.052 ms
Binary, $uuid->bytes
read in 0.045 ms
Saved by binary
20,000 bytes
e0c24b9c-db26-4409-97c7-2e65ba985dd1e0c24b9cdb26440997c72e65ba985dd1This demo runs webpatser/uuid 3.0.0, the version installed on this site.
From binary and hex
import() accepts 16 raw bytes, hex without hyphens, hyphenated strings and urn:uuid: strings.
$fromBinary = Uuid::import($binary);$fromHex = Uuid::import('6ba7b8109dad11d180b400c04fd430c8');$fromUrn = Uuid::import('urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8'); echo $fromBinary->string === $uuid->string ? 'same' : 'different'; // same
Input that is neither 16 bytes nor 32 hex digits (after stripping urn:uuid: and non-hex characters) throws a TypeError. Any 16-byte string is accepted as raw bytes. validate() only accepts the hyphenated form, so it cannot be used to check binary or plain hex input.
Time-ordered hex
uuid_ordered returns 16 hex characters: the time fields only, reordered (time high, time mid, time low). It is not a full UUID and cannot be imported back.
$uuid = Uuid::generate(1); echo $uuid->uuid_ordered;
Comparing
compare() normalizes both sides before comparing, so binary and string forms can be mixed:
Uuid::compare($uuid->bytes, $uuid->string); // true
SQL Server
SQL Server uses a different byte order. Use toSqlServerBinary() and importFromSqlServer() instead of bytes and import() there: Microsoft SQL Server.