Is there an integer equivalent of __toString()
<p>Is there a way to tell PHP how to convert your objects to ints? Ideally it would look something like</p>

<pre><code>class ExampleClass
{
    ...

    public function __toString()
    {
        return $this-&gt;getName();
    }

    public function __toInt()
    {
        return $this-&gt;getId();
    }
}
</code></pre>

<p>I realize it's not supported in this exact form, but is there an easy (not-so-hacky) workaround?</p>

<p>---------------------- EDIT EDIT EDIT -----------------------------</p>

<p>Thanks everybody! The main reason I'm looking into this is I'd like to make some classes (form generators, menu classes etc) use objects instead of arrays(uniqueId => description). This is easy enough if you decide they should work only with those objects, or only with objects that extend some kind of generic object superclass.</p>

<p>But I'm trying to see if there's a middle road: ideally my framework classes could accept either integer-string pairs, or objects with getId() and getDescription() methods. Because this is something that must have occurred to someone else before I'd like to use the combined knowledge of stackoverflow to find out if there's a standard / best-practice way of doing this <strong>that doesn't clash with the php standard library, common frameworks etc</strong>.</p>
