PHP code example of puzzle / uuid

1. Go to this page and download the library: Download puzzle/uuid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

puzzle / uuid example snippets




// Generate a valid uuid
$uuid = new Uuid();

// Force uuid value
$uuid = new Uuid('b85873d1-7968-4f83-94f7-3bb6bc111828');

function foo(Uuid $uuid)
{
    // $uuid is valid !
}




final class PonyId extends SelfValidatedUuid {}

class Pony
{
    private $id;

    public function __construct(?PonyId $id = null)
    {
        if($id === null)
        {
            $id = new PonyId();
        }
        
        $this->id = $id;
    }
    
    //...
}