Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49225 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65628 invoked from network); 9 Aug 2010 11:47:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2010 11:47:06 -0000 Authentication-Results: pb1.pair.com smtp.mail=mathieu.suen@easyflirt.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=mathieu.suen@easyflirt.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain easyflirt.com designates 91.199.255.56 as permitted sender) X-PHP-List-Original-Sender: mathieu.suen@easyflirt.com X-Host-Fingerprint: 91.199.255.56 python-06.easyrencontre.com Linux 2.6 Received: from [91.199.255.56] ([91.199.255.56:46641] helo=mail.easyflirt.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E9/AD-63845-9BAEF5C4 for ; Mon, 09 Aug 2010 07:47:06 -0400 Received: from [192.168.0.51] (office.easyrencontre.com [78.155.152.6]) by mail.easyflirt.com (Postfix) with ESMTPSA id 18CB5637505; Mon, 9 Aug 2010 13:47:03 +0200 (CEST) Message-ID: <4C5FEAB7.7000603@easyflirt.com> Date: Mon, 09 Aug 2010 13:47:03 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: RQuadling@googlemail.com CC: PHP internals References: <4C5C1D2E.6070805@easyflirt.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------090500080700080204030205" Subject: Re: [PHP-DEV] Indexing an array From: mathieu.suen@easyflirt.com ("mathieu.suen") --------------090500080700080204030205 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 08/06/2010 04:44 PM, Richard Quadling wrote: > On 6 August 2010 15:33, mathieu.suen wrote: > >> Hi, >> >> For now you can only index an array using a scalar type or a string. >> Is there some rfc or work going on to enlarge the possibility so that it is >> possible to have some other object like: >> >> - closure >> - object >> - etc. >> >> Thanks >> >> -- Mathieu Suen >> > If an object implements a __toString() magic method, then it can work ... > > > class randomizer { > public function __toString() { > return (string)mt_rand(); > } > } > > $randomizer = new randomizer; > $array = array ( > "$randomizer" => 'First', > "$randomizer" => 'Second', > "$randomizer" => 'Third', > "$randomizer" => 'Fourth', > ); > > print_r($array); > ?> > > outputs ... > > Array > ( > [1365443950] => First > [1235256771] => Second > [520059180] => Third > [486985268] => Fourth > ) Well that is not the expected behavior since if you call array_keys you won't get the object. --Mathieu Suen --------------090500080700080204030205--