title: Convert python uuid hashing code to php
body: <p>I'm trying to port large chunk of python code to php - while doing so I've found this one line which I can't find equivalent for:</p>
  
  <pre><code>    instance = resp.get(
          'instance',
          uuid.uuid4().hex.encode('utf-8')
      )
  
      sha = hashlib.sha1(
          self.username.encode('utf-8') + instance
      )
      self.params.update({'id': sha.hexdigest().upper()})
  </code></pre>
  
  <p>I've found <a href="https://github.com/ramsey/uuid" rel="nofollow">https://github.com/ramsey/uuid</a> to generate uuid4 and tried to mimic above like so:</p>
  
  <pre><code>    if (isset($resp['instance']))
      {
          $instance = $resp['instance'];
      }
      else
      {
          $uuid4 = Uuid::uuid4();
          $instance = utf8_encode(dechex($uuid4-&gt;toString()));
      }
  
      $sha = sha1(utf8_encode($this-&gt;username) . $instance);
  
      $this-&gt;params['id'] = strtoupper($sha);
  </code></pre>
  
  <p>This does not seem to provide same results. Can anyone help me out to produce same result in php as in python. Thanks.</p>