Is there an integer equivalent of __toString()

KokKeong

New Member
Is there a way to tell PHP how to convert your objects to ints? Ideally it would look something like\[code\]class ExampleClass{ ... public function __toString() { return $this->getName(); } public function __toInt() { return $this->getId(); }}\[/code\]I realize it's not supported in this exact form, but is there an easy (not-so-hacky) workaround?---------------------- EDIT EDIT EDIT -----------------------------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.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 that doesn't clash with the php standard library, common frameworks etc.
 
Back
Top