Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:23947 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83088 invoked by uid 1010); 5 Jun 2006 00:16:42 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 83073 invoked from network); 5 Jun 2006 00:16:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jun 2006 00:16:42 -0000 X-PHP-List-Original-Sender: adam@trachtenberg.com X-Host-Fingerprint: 216.93.242.2 miranda.org Linux 2.4/2.6 Received: from ([216.93.242.2:55197] helo=miranda.org) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id C3/C0-00946-AE773844 for ; Sun, 04 Jun 2006 20:16:42 -0400 Received: (qmail 28161 invoked by uid 546); 4 Jun 2006 20:16:39 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 4 Jun 2006 20:16:39 -0400 Date: Sun, 4 Jun 2006 20:16:39 -0400 (EDT) X-X-Sender: adam@miranda.org To: Andrei Zmievski cc: Marcus Boerger , PHP Internals , Dmitry Stogov , Andi Gutmans , Zeev Suraski , Ilia Alshanetsky In-Reply-To: <754ED3FF-418F-4E7F-A7A8-B1C0A1B59AFB@gravitonic.com> Message-ID: References: <795156743.20060603134212@marcus-boerger.de> <754ED3FF-418F-4E7F-A7A8-B1C0A1B59AFB@gravitonic.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] Missing __toString() part From: adam@trachtenberg.com (Adam Maccabee Trachtenberg) On Sun, 4 Jun 2006, Andrei Zmievski wrote: > I am sorry if I missed the whole thread. I think that using the > result of __toString() for indexing objects is a bad idea. If we want > to allow this behavior (which is actually useful in some situations), > I'd rather we had a __hash() method or something similar to what > Python does. The string representation of the object and its hashed > representation may be very different. After sitting on the fence on this one for a few days, I agree with Andrei. For example, for an eBay Item object, my __toString() returns the Title, but that's not unique, so my __toHash() returns the numeric ID, which is. Furthermore, if my __toString() was unique, and I was relying on that for keys in an array, I would have to mark that method as final; otherwise, someone might unknowingly destroy the uniqueness in a child class and break my code. That's not ideal because there could otherwise be many good reasons that someone would want to override __toString(). In contrast, it's unlikely that you would override __toHash(), and it's pretty obvious that you shouldn't do something that could cause collisions. The other proposal, where PHP generates a unique object id, would also be fine. Even better, perhaps. I'm not sure what I think yet. -adam -- adam@trachtenberg.com | http://www.trachtenberg.com author of o'reilly's "upgrading to php 5" and "php cookbook" avoid the holiday rush, buy your copies today!