Skip to content

Instantly share code, notes, and snippets.

@gorkaio
Last active September 9, 2016 22:56
Show Gist options
  • Save gorkaio/1331ee8751ac15a61a9794664014528f to your computer and use it in GitHub Desktop.
Save gorkaio/1331ee8751ac15a61a9794664014528f to your computer and use it in GitHub Desktop.
PHP UUID
<?php
// See https://benramsey.com/projects/ramsey-uuid/
// Install ramsey/uuid through composer and use the following snippet:
require 'vendor/autoload.php';
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
try {
// Generate a version 4 (random) UUID object
$uuid4 = Uuid::uuid4();
echo $uuid4->toString() . "\n";
} catch (UnsatisfiedDependencyException $e) {
// Some dependency was not met. Either the method cannot be called on a
// 32-bit system, or it can, but it relies on Moontoast\Math to be present.
echo 'Caught exception: ' . $e->getMessage() . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment