Re: Invokation on __toString() for object used as array key

From: Date: Tue, 23 Sep 2014 09:45:26 +0000
Subject: Re: Invokation on __toString() for object used as array key
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-77521@lists.php.net to get a copy of this message
On 23 September 2014 10:35, Michael Wallner <mike@php.net> wrote: > On 2014-09-23 11:15, Leigh wrote: >> He doesn't want to add the object as a key, he wants to invoke __toString(). > > Did I write that? No, you didn't, sorry. I just didn't see how an object with an explicit method to convert it to a string compared to using a resource straight up as a key. If you were implying the resource would be cast to int, then I get the comparison. Does it really make bugs that hard to find? You'd expect the user to know when they're using this behaviour when they write the code... well, I would. I suppose explicit casting removes any ambiguity, we use $a[(int)$resource] all the time for arrays of sockets and that's served us fine over the years. Hmm, thinking about it $a[(string)$object] is a lot clearer than having some magic sort it out. You're right, I'll retreat now :)

« previous php.internals (#77521) next »