Last active
September 9, 2016 22:56
-
-
Save gorkaio/1331ee8751ac15a61a9794664014528f to your computer and use it in GitHub Desktop.
PHP UUID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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