Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77588 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78280 invoked from network); 24 Sep 2014 19:45:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Sep 2014 19:45:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:55186] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/43-57585-36F13245 for ; Wed, 24 Sep 2014 15:45:39 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id B7A6D2400C2; Wed, 24 Sep 2014 15:45:35 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id cNZqiz_TxX9R; Wed, 24 Sep 2014 15:45:35 -0400 (EDT) Received: from oa-res-27-90.wireless.abdn.ac.uk (oa-res-27-90.wireless.abdn.ac.uk [137.50.27.90]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 4EB8C2400D0; Wed, 24 Sep 2014 15:45:33 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <1411561476.2303.4.camel@guybrush> Date: Wed, 24 Sep 2014 20:45:31 +0100 Cc: Nicolai Scheer , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <1411561476.2303.4.camel@guybrush> To: =?windows-1252?Q?Johannes_Schl=FCter?= X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] Invokation on __toString() for object used as array key From: ajf@ajf.me (Andrea Faulds) On 24 Sep 2014, at 13:24, Johannes Schl=FCter = wrote: > Taking this sample code::: >=20 > class C { > function __toString() { > return "C"; > } > } >=20 > $a =3D []; >=20 > $c1 =3D new C(); > $c2 =3D new C(); >=20 > $a[$c1] =3D 23; > $a[$c2] =3D 42; > ?> >=20 > There the assumption would be that this leads to an array $a with two > elements, where in fact there is only one if __toString() is being > called. The only thing "making sense" would be using using the objects > identity (i.e. via spl_object_hash()) everything else leads to issues. I=92m not sure this is a fair example. Don=92t classes usually implement = a `__toString()` that is based on the data they contain? If they don=92t, = I=92m not sure they=92re useful for indexing anyway. -- Andrea Faulds http://ajf.me/