Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:23885 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76900 invoked by uid 1010); 3 Jun 2006 14:38:45 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 76884 invoked from network); 3 Jun 2006 14:38:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jun 2006 14:38:45 -0000 X-PHP-List-Original-Sender: andrew@plexpod.com X-Host-Fingerprint: 147.202.47.146 cruiser.plexpod.net Linux 2.5 (sometimes 2.4) (4) Received: from ([147.202.47.146:41142] helo=cruiser.plexpod.net) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id AF/0D-22639-4FE91844 for ; Sat, 03 Jun 2006 10:38:45 -0400 Received: from dsl254-067-175.nyc1.dsl.speakeasy.net ([216.254.67.175] helo=desario.homelinux.net) by cruiser.plexpod.net with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.52) id 1FmXGp-0006X5-Pi; Sat, 03 Jun 2006 10:38:32 -0400 Received: by desario.homelinux.net (sSMTP sendmail emulation); Sat, 3 Jun 2006 10:36:39 -0400 Date: Sat, 3 Jun 2006 10:36:39 -0400 To: Marcus Boerger Cc: internals@lists.php.net, Dmitry Stogov , Andi Gutmans , Zeev Suraski , Ilia Alshanetsky Message-ID: <20060603143639.GF5355@desario.homelinux.net> References: <795156743.20060603134212@marcus-boerger.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <795156743.20060603134212@marcus-boerger.de> User-Agent: Mutt/1.5.11 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cruiser.plexpod.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - plexpod.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] Missing __toString() part From: andrew@plexpod.com (Andrew Yochum) On Sat, Jun 03, 2006 at 01:42:12PM +0200, Marcus Boerger wrote: > Hello guys, > > the attached patch closes one more __toString() part. It allows > to use objects that define __toString as indexes to arrays. What do > you guys think about this, should we add it or stay with the old > behavior that didn't allow objects as indexes at all. Like others who have contributed to the thread I agree that it would be useful, but I think using __toString() wrong for this. There is a confusion two ideas here: 1. The string representation of an object, probably human readable, lucent string. 2. A unique hash of an object use to identify it programmatically, and likely unique. Probably a non-human friendly, opaque value. These are not the same thing. The latter is what, IMO, would be used for an objects value as an index into an array, not the former. The latter is available ... currently I do this like so: class a{ public function __toString() { return 'an object';}} $foo = new a; $bar = new a; $arr = new array() $arr[(string)$foo] = $foo; // The index is "Object id #1" $arr[(string)$bar] = $bar; // The index is "Object id #2" Note that the __tostring method is not used in the cast - a spearate issue, but needs to be pointed out for this issue. Therefore my suggested alternative to Marcus' patch is: When Objects are used in array index context, use the object ID or some variation. And, possibly, provide a magic method, or interface to generate an hash value of an object. Regards, Andrew -- Andrew Yochum Plexpod andrew@plexpod.com 718-360-0879