PHP: compareTo similar to Java
<p>In an effort to utilize OOP in PHP, I was looking for a way to define functions within objects to use for sorting. in Java this is simple, as the <code>compareTo()</code> is automatically called by sorted arrays and such. I looked around PHP.net and couldn't find anything similar in PHP. I have resorted to what seems like a hack to me, so I'm wondering if anyone can lend some insight on an easier way.</p>

<p>CURRENT CODE: </p>

<pre><code>class SomeObject {
    private $someField;

    function getSomeField() { return $this-&gt;someField; }

    function compareTo($other) {
        return $this-&gt;someField - $other-&gt;getSomeField();
    }
}

//in funcs.php
function objSort($a, $b) {
    return $a-&gt;compareTo($b);
}


//To sort an array
usort($array, objSort);
</code></pre>

<p>Is there an easier/more sleek way of doing this in PHP?</p>
