title: PHP - hash objects in a way distint object with same fields values have same hash
body: <p>I am looking for a way to generate some kind of hash for PHP object (generic solution, working with all classed, built-in and custom, if possible). </p>
  
  <p>SplObjectStorage::getHash is not what I'm looking for, as it will generate different hash for every instance of given class. To picture the problem, let's consider simple class:</p>
  
  <pre><code>class A() {
  public $field; //public only for simplicity
  }
  </code></pre>
  
  <p>and 2 instances of that class:</p>
  
  <pre><code>$a = new A(); $a-&gt;field = 'b';
  $b = new A(); $b-&gt;field = 'b';
  </code></pre>
  
  <p>Every built-in function I've tried will return different hashes for these objects, while I'd like to have some <code>function f($x)</code> with property <code>f($a) == f($b) =&gt; $a == $b</code>. </p>
  
  <p>I am aware I could write a function traversing all object's properties recursively until I find a property that can be casted to string, concatenate this strings in fancy way and hash, but the performance of such solution would be awful.</p>
  
  <p>Is there an efficient way to do this? </p>