title: php overload equals-operator
body: <p>In a PHP program I have an array of some custom objects, and I want to find if the array contains a certain object. Of course I can use array_search, but this checks if the objects are the same object, not if it has the same variables. So I want to be able to create my own compare function for the objects, which I can use with the array_search method (or something similar).
  I want to be able to do something like this:</p>
  
  <pre><code>class foo
  {
      public $_a,$_b;
      function __construct($a,$b)
      {
          $this-&gt;_a = $a;
          $this-&gt;_b = $b;
      }
  
      function __equals($object)
      {
          return $this-&gt;_a == $object-&gt;_a;
      }
  }
  $f1 = new foo(5,4);
  $f2 = new foo(4,6);
  $f3 = new foo(4,5);
  
  $array = array($f1,$f2);
  $idx = array_search($f3,$array); // return 0
  </code></pre>
  
  <p>Is something like this possible?
  I know I can also create my own array_search method which uses a method from the class, but than I'd have to use 2 different search functions, one for the classes which do have their own compare function, and one for those which haven't.</p>