Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49230 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4360 invoked from network); 9 Aug 2010 14:26:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2010 14:26:00 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:36084] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/81-30416-3FF006C4 for ; Mon, 09 Aug 2010 10:25:57 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 993E5700E8AE for ; Mon, 9 Aug 2010 15:25:52 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id wkU-jTI+zq9A for ; Mon, 9 Aug 2010 15:25:52 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 4DE89700043E for ; Mon, 9 Aug 2010 15:25:52 +0100 (WEST) Received: from cataphract (a83-132-178-216.cpe.netcabo.pt [83.132.178.216]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 41BE520010DA for ; Mon, 9 Aug 2010 15:25:52 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <4C5C1D2E.6070805@easyflirt.com> <4C5FEA03.8010801@easyflirt.com> Date: Mon, 09 Aug 2010 15:24:52 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_IST?= Message-ID: In-Reply-To: <4C5FEA03.8010801@easyflirt.com> User-Agent: Opera Mail/10.60 (Win32) Subject: Re: [PHP-DEV] Indexing an array From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Mon, 09 Aug 2010 12:44:03 +0100, mathieu.suen wrote: > On 08/06/2010 04:42 PM, Gustavo Lopes wrote: >> On Fri, 06 Aug 2010 15:33:18 +0100, mathieu.suen >> wrote: >> >>> 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. >> >> I think the problem with that is how you are going to generate the >> hash of arbitrary objects in order to store them in the hash table. >> It's not like all PHP objects have a hashCode() method. > > IMHO It should. > >> >> So the only plausible option would be to attribute the same hash to >> all and the test all for equality on an insertion with a new key or in >> the worst case scenario for updates and reads. >> > > Since php is not referentially transparent I would rather use identity > unless object can redefine equality. > Well, even if one could overcome the hash problem by using suboptimal methods like calling __toString (or even use spl_object_hash(), though we'd be limited to identity) as if they were hashCode() methods, one big problem remains: the hash tables only store a simple integer (for numerical indexing) or a char * string (for string indexing) to identify the key. It would have to be changed to be able to store an object, and now we'd break a lot of code that expects keys to be either strings or integers, not to mention the arrays API would be more complicated that it already is. SplObjectStorage is a so-so alternative because it only allows identity in indexing, but you seem to be OK with that. As to it not working with array functions, you're right, it sucks. In fact, only array_key_exists and array_walk(_recursive) work with object (if you can call it "work"). Perhaps one path here is to change the array functions so that if they receive an object they try to cast it into an array with the cast_object handler/convert_object_to_type and change the current default implementation for standard objects, which only handles conversions to string, to also handle conversions to arrays by traversing the object, if possible. Not the most efficient thing to do, since it requires copying everything, but it would be easier than changing the array functions in a more profound fashion. The "H" parse argument is useless because it tries to call get_properties (by the way, I don't understand why convert_to_array(_ex) and convert_to_explicit_type prefer get_properties to cast_object). -- Gustavo Lopes