PHPackages                             philiprehberger/php-uuid-tools - 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. [Database &amp; ORM](/categories/database)
4. /
5. philiprehberger/php-uuid-tools

ActiveLibrary[Database &amp; ORM](/categories/database)

philiprehberger/php-uuid-tools
==============================

UUID v4 and v7 generation, validation, and ordered UUIDs for database indexing

v1.0.2(1mo ago)11[1 PRs](https://github.com/philiprehberger/php-uuid-tools/pulls)MITPHPPHP ^8.2CI passing

Since Mar 13Pushed 1mo agoCompare

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

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

PHP UUID Tools
==============

[](#php-uuid-tools)

[![Tests](https://github.com/philiprehberger/php-uuid-tools/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-uuid-tools/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/5aaf68d5b8db93929a805ecae6b9cfd4d8374b9cbf240afa1feac1c44331870a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d757569642d746f6f6c732e737667)](https://packagist.org/packages/philiprehberger/php-uuid-tools)[![License](https://camo.githubusercontent.com/7e0b95fb6c71b10cf394e2a2c0be6a4349b54054787115d77d89fdbe1a74f259/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f7068702d757569642d746f6f6c73)](LICENSE)

UUID v4 and v7 generation, validation, and ordered UUIDs for database indexing.

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

[](#requirements)

- PHP 8.2+

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

[](#installation)

```
composer require philiprehberger/php-uuid-tools
```

Usage
-----

[](#usage)

### Generate UUID v4

[](#generate-uuid-v4)

```
use PhilipRehberger\UuidTools\Uuid;

$uuid = Uuid::v4();
// "f47ac10b-58cc-4372-a567-0e02b2c3d479"
```

### Generate UUID v7

[](#generate-uuid-v7)

Time-ordered UUIDs with millisecond precision, ideal for database primary keys:

```
$uuid = Uuid::v7();
// "018e4f6c-1a2b-7000-8000-1234567890ab"
```

### Validate a UUID

[](#validate-a-uuid)

```
Uuid::isValid('550e8400-e29b-41d4-a716-446655440000'); // true
Uuid::isValid('not-a-uuid');                            // false
```

### Extract Version

[](#extract-version)

```
Uuid::version('550e8400-e29b-41d4-a716-446655440000'); // 4
Uuid::version('invalid');                               // null
```

### Binary Conversion

[](#binary-conversion)

Convert between UUID strings and 16-byte binary for compact storage:

```
$bytes = Uuid::toBytes('550e8400-e29b-41d4-a716-446655440000');
// 16-byte binary string

$uuid = Uuid::fromBytes($bytes);
// "550e8400-e29b-41d4-a716-446655440000"
```

### Ordered UUIDs

[](#ordered-uuids)

Reorder UUID fields for optimal database index performance. Puts the most-significant time bits first so UUIDs sort chronologically:

```
$uuid = Uuid::v7();
$ordered = Uuid::toOrdered($uuid);

// Store $ordered in the database for better index locality

$original = Uuid::fromOrdered($ordered);
// Recovers the original UUID
```

### Nil UUID

[](#nil-uuid)

```
$nil = Uuid::nil();
// "00000000-0000-0000-0000-000000000000"
```

API
---

[](#api)

MethodDescription`Uuid::v4(): string`Generate a random UUID v4`Uuid::v7(): string`Generate a time-ordered UUID v7`Uuid::isValid(string $uuid): bool`Validate a UUID string (any version)`Uuid::version(string $uuid): ?int`Extract the version number (null if invalid)`Uuid::toBytes(string $uuid): string`Convert UUID to 16-byte binary`Uuid::fromBytes(string $bytes): string`Convert 16-byte binary to UUID string`Uuid::toOrdered(string $uuid): string`Reorder UUID for database index performance`Uuid::fromOrdered(string $ordered): string`Reverse an ordered UUID to standard format`Uuid::nil(): string`Return the nil UUID (all zeros)Development
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance89

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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

Total

3

Last Release

56d ago

### Community

Maintainers

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

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (11 commits)")

---

Tags

validationdatabaseuuidorderedv4v7

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-php-uuid-tools/health.svg)

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

###  Alternatives

[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[codezero/laravel-unique-translation

Check if a translated value in a JSON column is unique in the database.

186965.1k7](/packages/codezero-laravel-unique-translation)[openbuildings/jam

Small but feature rich ORM, has extensible models and builders, baked in upload functionality, supporting multiple backends (rackspace, ftp), polymorphic associations, form builders, nested forms, validators

32181.3k16](/packages/openbuildings-jam)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

845.7k](/packages/tommyknocker-pdo-database-class)[weebly/laravel-mutate

Mutate Laravel attributes

1354.7k](/packages/weebly-laravel-mutate)[jrsaunders/shard-matrix

A Complete Database Sharding system for MYSQL and/or Postgres. Using Laravels Query Builder easily scale up your application. Configure your whole solution in one Yaml Config file.

271.5k](/packages/jrsaunders-shard-matrix)

PHPackages © 2026

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