PHPackages                             pwm/uuid-v4 - 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. pwm/uuid-v4

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

pwm/uuid-v4
===========

Implementation of the RFC 4122 UUID version 4 (variant 1) data type

1.0.1(7y ago)62.2kMITPHPPHP &gt;=7.1.0

Since Jun 11Pushed 7y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (3)Used By (0)

UUID version 4
==============

[](#uuid-version-4)

[![Build Status](https://camo.githubusercontent.com/de9167ed4b35f9c7c7ba7943a35cb4a38821e5f2018c75ddb3d8877e060633a6/68747470733a2f2f7472617669732d63692e6f72672f70776d2f757569642d76342e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pwm/uuid-v4)[![codecov](https://camo.githubusercontent.com/8dbc0a5e5a9045bbd665d474918f8a009cd2c03657ccb2fa9950a4209f8b9978/68747470733a2f2f636f6465636f762e696f2f67682f70776d2f757569642d76342f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/pwm/uuid-v4)[![Maintainability](https://camo.githubusercontent.com/ce053b3d891cdbff84986402a6d98f614a2ee413ddd701a55c9789b2f9c6f1ae/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35613164376361653132353332333236306539362f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/pwm/uuid-v4/maintainability)[![Test Coverage](https://camo.githubusercontent.com/6d272806b7ceebf1fe6f6d4aafa8d2f7a2e26579b87c6c21d513e6458631b3c6/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35613164376361653132353332333236306539362f746573745f636f766572616765)](https://codeclimate.com/github/pwm/uuid-v4/test_coverage)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

Implementation of the [RFC 4122](https://tools.ietf.org/html/rfc4122) UUID version 4 (variant 1) data type. UUID stands for Universally Unique Identifier.

Table of Contents
-----------------

[](#table-of-contents)

- [Why](#why)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [How it works](#how-it-works)
- [Tests](#tests)
- [Changelog](#changelog)
- [Licence](#licence)

Why
---

[](#why)

We already have comprehensive UUID libraries in PHP, eg. [ramsey/uuid](https://github.com/ramsey/uuid).

My goal was to create a minimalistic implementation of the version 4 UUID spec. UUIDv4-s are randomly generated which makes implementation trivial as it requires nothing other than a random external seed value.

The decision to only implement version 4 resulted in a tiny functional library capturing the UUIDv4 data type that can be understood in minutes. Creation happens using a pure function that takes the random seed and is trivially testable.

Requirements
------------

[](#requirements)

PHP 7.1+

Installation
------------

[](#installation)

```
$ composer require pwm/uuid-v4

```

Usage
-----

[](#usage)

Creating a UUIDv4 data type from a valid string:

```
$uuidV4String = '30313233-3435-4637-b839-616263646566';

$uuidV4 = new UuidV4($uuidV4String); // the data type

assert($uuidV4 instanceof UuidV4);
assert($uuidV4String === (string)$uuidV4);
```

Creating a random UUIDv4 from a 16 byte random seed:

```
$uuidV4 = UuidV4::createFrom(random_bytes(16));

assert($uuidV4 instanceof UuidV4);
```

Creating from the same seed produces the same UUIDv4:

```
$seed = random_bytes(16);

assert((string)UuidV4::createFrom($seed) === (string)UuidV4::createFrom($seed));
```

How it works
------------

[](#how-it-works)

UUID version 4 is defined in [RFC 4122](https://tools.ietf.org/html/rfc4122) as a sequence of 128 bits, where 6 bits are fixed (4 for the version, 2 for the variant) leaving 122 randomly generated bits for entropy.

`UuidV4` is a simple data type that can only be created from valid UUIDv4 strings. It comes with a `createFrom()` function that facilitates the creation of random UUIDv4-s from 16 byte random seeds. It is to be used with PHP's `random_bytes()` function.

Tests
-----

[](#tests)

```
$ vendor/bin/phpunit
$ composer phpcs
$ composer phpstan
$ composer infection

```

Changelog
---------

[](#changelog)

[Click here](changelog.md)

Licence
-------

[](#licence)

[MIT](LICENSE)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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 ~0 days

Total

2

Last Release

2888d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/361d01dea838dfee1327e7c6e803e7f53ae92b48d6971bcaeca43d3d49504c19?d=identicon)[pwm](/maintainers/pwm)

---

Top Contributors

[![pwm](https://avatars.githubusercontent.com/u/195513?v=4)](https://github.com/pwm "pwm (5 commits)")

---

Tags

uuid v4

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[zamoose/themehookalliance

Theme Hook Alliance

37010.4k](/packages/zamoose-themehookalliance)

PHPackages © 2026

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