Re: Missing __toString() part
| From: | Rasmus Lerdorf | Date: | Sun, 04 Jun 2006 01:50:09 +0000 |
| Subject: | Re: Missing __toString() part | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-23901@lists.php.net to get a copy of this message | ||
Alan Knowles wrote:
$x = new Obj; $y[$x]= 123; That behaviour is going to be fun to document, and for people unfamilar with it to find in the manual -> php.net/array -> go to array syntax page -> read down to find about objects as keys -> go to __toHash() page... ..whereas... $x = new Obj; $y[$x->toHash()]= 123; they might have a chance to see instantly how that is supposed to work, on the rare occasion that somebody needs this, is it really worth building it into the langauge????In that case, why not just use the existing __toString explicitly with: $x = new Obj; $y[(string)$x] = 123; This works today and basically gives you the same thing. The only thing it doesn't do is separate an array index context from an output context allowing you do different things in the two cases. I think if we are going to add a toHash thing, it should trigger when the object is used in a hash context, just like toString triggers when it is used in a string context. -Rasmus