jewei.toString()

TypeID PHP: Type-Safe, Sortable IDs for PHP

A PHP library for TypeIDs: UUIDv7 with a type prefix, like user_01h455vb4pex5vsknk084sn02q. Sortable, URL-safe, and one composer require away.

Update (May 2026): v1.1 has been released! The minimum supported PHP version is now 8.4, and all tests fully pass against the official specification.

TypeID PHP brings type-safe, globally unique identifiers to your PHP projects. This library implements TypeIDs - an elegant extension of UUIDv7 that adds descriptive type prefixes to identifiers.

Instead of working with opaque UUIDs like 01890a5d-ac96-774b-bcce-b302099a8057, you get human-readable IDs like user_01h455vb4pex5vsknk084sn02q that instantly communicate their purpose.

Why Use TypeID?#

  • Type Safety: Prevent errors by distinguishing between different entity types
  • Intuitive Debugging: Immediately identify what an ID represents
  • Database Performance: K-sortable for better index locality
  • Space Efficiency: URL-safe base32 encoding (26 characters vs 36 for UUIDs)

Quick Example#

PHP
// Generate a user ID
$userId = TypeID::generate('user');
// user_01h455vb4pex5vsknk084sn02q

// Create a product ID from an existing UUID
$productId = TypeID::fromUuid('product', $uuid);

TypeID PHP integrates seamlessly with existing systems while enhancing readability and safety. Install today with composer require jewei/typeid-php and bring more clarity to your identifiers.

To see where TypeIDs fit next to integer keys, read Database Primary Key: Integer vs UUID vs NanoID.

TypeID PHP (TypeID logo thumbnail)
PHP implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs

Written by Jewei Mak

Senior software engineer, working on backend systems and payments. New posts go to the RSS feed. If this one saved you time, you can sponsor the work.

Keep reading

All writing