Re: Missing __toString() part

From: Date: Sun, 04 Jun 2006 01:45:37 +0000
Subject: Re: Missing __toString() part
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-23900@lists.php.net to get a copy of this message
$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???? Regards Alan Andi Gutmans wrote:
Yep that is also a choice, although it can be advantageous to have an automatic (a) which people just now works, always... I don't think it's a critical problem because as you pointed out people can deal with it, but I think it'd be nice to provide some tools to make life easier. At 06:01 PM 6/3/2006, Pierre wrote:
Hi, On 6/4/06, Andi Gutmans <andi@zend.com> wrote:
Generally I think it's a good thing to allow to use objects as array indexes. There are really two ways of doing it: a) Try and find a way to create unique ideas. b) Support __toString() and leave it up to the author.
I see a third choice, which I prefer: c) leave the choice to the user, he knows better what to do with his object (like implementing his own get(Hash|Key) method. --Pierre


« previous php.internals (#23900) next »