PHPackages                             lootils/uuid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lootils/uuid

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lootils/uuid
============

A simple class for working with UUIDs.

1.0.2(12y ago)3381.4k↓40.4%11MITPHPPHP &gt;=5.3.0

Since Nov 2Pushed 12y ago4 watchersCompare

[ Source](https://github.com/lootils/uuid)[ Packagist](https://packagist.org/packages/lootils/uuid)[ Docs](https://github.com/lootils/lootils-uuid)[ RSS](/packages/lootils-uuid/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

Universally Unique Identifiers (UUID)
=====================================

[](#universally-unique-identifiers-uuid)

This PHP library, part of [Lootils](http://github.com/mattfarina/Lootils), creates and verifies RFC 4122 compliant version 3, 4, and 5 UUIDs.

[![Build Status](https://camo.githubusercontent.com/ca6c4e4eb3ec9797efb070709fb8f73db7d324e772de9893e82e8406a666fee8/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6d617474666172696e612f4c6f6f74696c732d555549442e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/mattfarina/Lootils-UUID) [![Latest Stable Version](https://camo.githubusercontent.com/a2fc78853e7e22a3ae52d59df72591a69e4ff357d145d97bec391bb146be51e1/68747470733a2f2f706f7365722e707567782e6f72672f6c6f6f74696c732f757569642f762f737461626c652e706e67)](https://packagist.org/packages/lootils/uuid) [![Coverage Status](https://camo.githubusercontent.com/41605656c0057e11efc1543dd9813ecb1e1ae0946eb6fb3e30b0e79176200669/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6c6f6f74696c732f757569642f62616467652e706e67)](https://coveralls.io/r/lootils/uuid)

For more information on UUIDs see

- [The Wikipedia Artice on UUIDs](https://en.wikipedia.org/wiki/UUID)
- [RFC 4122](https://tools.ietf.org/html/rfc4122)

UUID Versions
-------------

[](#uuid-versions)

This library works with 3 versions of UUIDs.

- Version 3: UUIDs generated based on a namespace and a name. Internally a MD5 hash is used. *Note: version 5 is preferred over version 3.*
- Version 4: Random UUIDs.
- Version 5: UUIDs generated based on a namespace and a name. Internally a sha1 hash is used.

Usage
-----

[](#usage)

I strongly suggest reading the code comments in uuid.php as it is well documented. Reading the tests may be helpful as well as there are examples in there.

### Validating a UUID format

[](#validating-a-uuid-format)

```
$valid = \Lootils\Uuid\Uuid::isValid($foo); // $valid will be a bool if it is valid or not.

```

### The UUID Object

[](#the-uuid-object)

The UUID object is one that can be created though its constructor but most often should happen via one of the version factirues in UUID::createV3, UUID::createV4, UUID::createV5.

Once an object is created there are a number of methods you can use. They include:

- listFields: This lists the available fields.
- getField: This returns the value for a passed in field name.
- getVersion: Returns the UUID version (3, 4, or 5) if it is known.
- getNamespace: Returns the namespace used to generate the UUID if it is known.
- getName: Returns the name used to generate the UUID if it is known.
- getURN: Returns a URN for the UUID.

If you print the uuid you will get it as a string. For example:

```
$uuid = \Lootils\Uuid\Uuid::createV4();
print $uuid; // This will display the UUID in the format 6ba7b810-9dad-11d1-80b4-00c04fd430c8.

```

If you are not using one of the factories you can create the an object using the following arguments:

```
$uuid = new \Lootils\Uuid\Uuid($uuid, $version, $namespace, $name);

```

The arguments are in the form:

- $uuid: The UUID as can be supplied in 4 different formats.

    - As a hex string in the format '{6ba7b810-9dad-11d1-80b4-00c04fd430c8}'.
    - Via a URN with the format 'urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8'.
    - Though an array in the form array('35e872b4', '190a', '5faa', 'a0', 'f6', '09da0d4f9c01').
    - With an array where the keys are the field names as seen on the listField method.
- $version: The version if known. Could be Uuid::V3, Uuid::V4, Uuid::V5.
- $namespace: For v3 and v5, the namespace used if it is known..
- $name: For v3 and v5, the name used if it is known.

### Creating a Random UUID

[](#creating-a-random-uuid)

```
$uuid = \Lootils\Uuid\Uuid::createV4(); // $uuid is now a random UUID.

```

### Creating a v5 UUID

[](#creating-a-v5-uuid)

```
$uuid = \Lootils\Uuid\Uuid::createV5(\Lootils\Uuid\Uuid::URL, 'http://example.com/foo.html');

```

### Verifying a v5 UUID

[](#verifying-a-v5-uuid)

If you know the namespace and name for a v5 UUID you can recreate and verify it. UUIDs created with the same namespace and name will always be the same. For example:

```
$uuid1 = \Lootils\Uuid\Uuid::createV5(\Lootils\Uuid\Uuid::URL, 'http://example.com/foo.html');
$uuid2 = \Lootils\Uuid\Uuid::createV5(\Lootils\Uuid\Uuid::URL, 'http://example.com/foo.html');

```

In this case `$uuid1` is equal to `$uuid2`.

### Creating a v3 UUID

[](#creating-a-v3-uuid)

```
$uuid = \Lootils\Uuid\Uuid::createV3(\Lootils\Uuid\Uuid::URL, 'http://example.com/foo.html');

```

### Verifying a v3 UUID

[](#verifying-a-v3-uuid)

If you know the namespace and name for a v3 UUID you can recreate and verify it. UUIDs created with the same namespace and name will always be the same. For example:

```
$uuid1 = \Lootils\Uuid\Uuid::createV3(\Lootils\Uuid\Uuid::URL, 'http://example.com/foo.html');
$uuid2 = \Lootils\Uuid\Uuid::createV3(\Lootils\Uuid\Uuid::URL, 'http://example.com/foo.html');

```

In this case the uuid hex string value for `$uuid1` is equal to `$uuid2`.

### Creating a Custom Namespace

[](#creating-a-custom-namespace)

If you want to create a custom namespace (like the URL and DNS ones) for your application you can do so with v3 or v5 methods and a NIL namespace. For example:

```
$namespace = \Lootils\Uuid\Uuid::createV5(\Lootils\Uuid\Uuid::NIL, 'my_app_name');

```

License
-------

[](#license)

This library was written by Matt Farina and is available under the MIT License.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~189 days

Total

3

Last Release

4567d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e009e68aaa3f72eb836b24c016afc08d8e7da904d10b65ba2982c9bcc6c02c19?d=identicon)[mattfarina](/maintainers/mattfarina)

---

Top Contributors

[![mattfarina](https://avatars.githubusercontent.com/u/62991?v=4)](https://github.com/mattfarina "mattfarina (29 commits)")

---

Tags

uuid

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lootils-uuid/health.svg)

```
[![Health](https://phpackages.com/badges/lootils-uuid/health.svg)](https://phpackages.com/packages/lootils-uuid)
```

###  Alternatives

[ramsey/uuid

A PHP library for generating and working with universally unique identifiers (UUIDs).

12.6k700.2M3.3k](/packages/ramsey-uuid)[symfony/polyfill-uuid

Symfony polyfill for uuid functions

688335.4M63](/packages/symfony-polyfill-uuid)[symfony/uid

Provides an object-oriented API to generate and represent UIDs

610280.0M754](/packages/symfony-uid)[webpatser/laravel-uuid

Laravel integration for webpatser/uuid - High-performance drop-in UUID replacements (15% faster than Ramsey). Provides Str macros, HasUuids trait, facades, and casts. RFC 4122/9562 compliant.

1.8k17.3M129](/packages/webpatser-laravel-uuid)[pascaldevink/shortuuid

PHP 7.4+ library that generates concise, unambiguous, URL-safe UUIDs

5951.8M15](/packages/pascaldevink-shortuuid)[emadadly/laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

120415.9k3](/packages/emadadly-laravel-uuid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
