A minimal, dependency-free GUID (Globally Unique Identifier) generator for PHP with a tiny runtime footprint. Frequently also called UUIDs (Universally Unique Identifiers).
If this package has been useful to you, GitHub Sponsors is a simple way to support ongoing maintenance, improvements, and future releases.
- PHP 8.2+
- Supported and CI-tested on PHP 8.2, 8.3, 8.4, and 8.5.
- Need legacy PHP support below 8.2? Use
sudiptpa/guid:^2.0.
composer require sudiptpa/guid<?php
declare(strict_types=1);
use Sujip\Guid\Guid;
$guid = new Guid();
echo $guid->create();
// Example: 2b23924f-0eaa-4133-848e-7ce1edeca8c9<?php
declare(strict_types=1);
echo guid();
// Example: 2b23924f-0eaa-4133-848e-7ce1edeca8c9
echo guid(false);
// Example: {2b23924f-0eaa-4133-848e-7ce1edeca8c9}Default usage is unchanged. If needed, provide your own generator:
<?php
declare(strict_types=1);
use Sujip\Guid\GeneratorInterface;
use Sujip\Guid\Guid;
final class CustomGenerator implements GeneratorInterface
{
public function generate(bool $trim = true): string
{
return $trim ? 'custom-guid' : '{custom-guid}';
}
}
$guid = new Guid(new CustomGenerator());
echo $guid->create(); // custom-guidThe package preserves the existing public behavior:
Sujip\Guid\Guid::create(bool $trim = true): stringguid(bool $trim = true): string
No runtime dependencies are required, and default usage stays a single class or helper call.
composer install
composer lint
composer stan
composer testSee CHANGELOG.md.
See CONTRIBUTING.md.
See MAINTAINERS.md.
MIT. See LICENSE.