Re: Missing __toString() part
| From: | Gwynne | Date: | Sat, 03 Jun 2006 21:15:50 +0000 |
| Subject: | Re: Missing __toString() part | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-23893@lists.php.net to get a copy of this message | ||
On Jun 3, 2006, at 1:13 PM, Rasmus Lerdorf wrote:
I'm new to this list, so I apologize if I'm out of line in commenting here, but it's my opinion that the advantages offered by a __hash() magic function would outweigh the inevitable complexity and issues involved. I imagine that it would be a strict semantic: If the class of the object being indexed into the array doesn't define a magic __hash() function, it would be a warning or even fatal error; no attempt would/should be made to calculate a hash based on anything other than what the object is willing to call itself. Gwynne SkyTag SoftwareRL>>I don't understand why using the object as an index would trigger a RL>>__toString() call. PHP's array indices are not defined to be strings, RL>>so I don't see this as being a string context use and thus RL>>__toString() shouldn't be called. If so, what should be the actual key in the hash?I am sure we could come up with some sort of hashing mechanism that would uniquely identify an object. And perhaps even expose it to the user with a __hashOf(). But again, I am not sure we want to open up that can of worms. Like I said, I think this is the more correct approach and that we shouldn't try to use a magic __toString() call here to attempt to emulate this.