~/docs
Resonate
Resonate
4.x 4.0.0, current 3.x 3.0.1 2.x 2.0.1 1.x 1.3.0
UUID Library
Toggle sidebar
UUID Library
webpatser/uuid 2.0.1
You are reading the 2.x documentation
The current line is 4.x. Read this page for 4.x

UUID Library 2.x

Upgrade Guide

Breaking changes and behaviour differences between webpatser/uuid 1.3.0 and 2.0.1.

This page covers 1.3.0 to 2.0.1. The repository has a CHANGELOG but no separate UPGRADE file.

Requirements

PHP ^8.5 is required (1.x: ^8.2). Update the constraint in composer.json:

{
"require": {
"webpatser/uuid": "^2.0"
}
}

Removed

Uuid::isSqlServerFormat() is gone. It only checked the string format and gave the same answer as validate(). Replace calls with Uuid::validate(), or convert explicitly with importFromSqlServer().

Behaviour changes

  • compare() returns false when either argument is not a valid UUID. In 1.x two unrelated invalid strings compared as equal. The comparison now uses hash_equals().
  • validate() is anchored with the D pattern modifier, so a trailing newline no longer passes.
  • The constructor, and so import(), rejects any input that is not exactly 16 bytes. 1.x let an empty string through that check.
  • Name-based generation throws Exception('Unsupported hash algorithm for name-based UUID.') instead of returning null on an unexpected hash algorithm.

Attributes

Factory and query methods now carry #[\NoDiscard]: generate(), v4(), v7(), import(), compare(), validate(), nil(), benchmark(), importFromSqlServer(), toSqlServer() and toSqlServerBinary(). PHP warns when you ignore their return value.

Additions

  • examples/benchmark.php for reproducible measurements.
  • The example scripts use the correct namespace and existing methods.

Development

The test suite moved from PHPUnit to Pest 4. This affects only contributors.

Unchanged

Method names and signatures, the property names, the namespace constants and the SQL Server conversion methods behave as in 1.3.0. Existing calls to v4(), v7(), generate(), import(), nil() and the properties need no change.

Checklist

  1. Upgrade PHP to 8.5 or newer.
  2. Run composer require webpatser/uuid:^2.0.
  3. Replace isSqlServerFormat() calls.
  4. Check code that relied on compare() returning true for two invalid inputs.
  5. Use the return value of every factory call to avoid #[\NoDiscard] warnings.

See also the 2.x installation page and the API reference.