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

From: Date: Tue, 23 Sep 2014 10:41:27 +0000
Subject: Re: Invokation on __toString() for object used as array key
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-77522@lists.php.net to get a copy of this message
On 2014-09-23 11:45, Leigh wrote: > 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 :) > I'm a "victim" of $array[(int) $resource] myself. I just tried to explain that the behavior is intentional and not an oversight. That doesn't mean that is set in stone for all times. -- Regards, Mike

« previous php.internals (#77522) next »