title: spl_object_hash for PHP < 5.2 (unique ID for object instances)
body: <p>I'm trying to get unique IDs for object instances in PHP 5+.</p>
  
  <p>The function, <a href="http://php.net/manual/en/function.spl-object-hash.php" rel="nofollow noreferrer"><code>spl_object_hash()</code></a> is available from PHP 5.2 but I'm wondering if there is a workaround for older PHP versions.</p>
  
  <p>There are a couple of functions in the comments on php.net but they're not working for me. The first (simplified):</p>
  
  <pre><code>function spl_object_hash($object){
      if (is_object($object)){
          return md5((string)$object);
          }
      return null;
      }
  </code></pre>
  
  <p>does not work with native objects (such as DOMDocument), and the second:</p>
  
  <pre><code>function spl_object_hash($object){
      if (is_object($object)){
          ob_start();
          var_dump($object);
          $dump = ob_get_contents();
          ob_end_clean();
          if (preg_match('/^object\(([a-z0-9_]+)\)\#(\d)+/i', $dump, $match)) {
              return md5($match[1] . $match[2]);
              }
          }
      return null;
      }
  </code></pre>
  
  <p>looks like it could be a major performance buster!</p>
  
  <p>Does anybody have anything up their sleeve?</p>