Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25660 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34510 invoked by uid 1010); 13 Sep 2006 11:59:51 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 34494 invoked from network); 13 Sep 2006 11:59:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Sep 2006 11:59:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=tslettebo@broadpark.no; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=tslettebo@broadpark.no; sender-id=unknown Received-SPF: error (pb1.pair.com: domain broadpark.no from 80.203.156.252 cause and error) X-PHP-List-Original-Sender: tslettebo@broadpark.no X-Host-Fingerprint: 80.203.156.252 mail.adstate.net Windows 2000 SP2+, XP SP1 (seldom 98 4.10.2222) Received: from [80.203.156.252] ([80.203.156.252:3229] helo=mail.adstate.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3A/8A-55513-4B2F7054 for ; Wed, 13 Sep 2006 07:59:50 -0400 Received: from localhost ([127.0.0.1]) by mail.adstate.net; Wed, 13 Sep 2006 09:52:59 +0200 Message-ID: <0ccc01c6d709$a18eb6c0$a900000a@adstate.local> To: "Marcus Boerger" Cc: References: <03ab01c6d6ff$6e38ab50$9a02a8c0@pc> <1985468657.20060913093035@marcus-boerger.de> Date: Wed, 13 Sep 2006 09:52:57 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1807 x-mimeole: Produced By Microsoft MimeOLE V6.00.2800.1807 Subject: Re: [PHP-DEV] Making ArrayAccess objects more array-like? From: tslettebo@broadpark.no (=?iso-8859-1?Q?Terje_Sletteb=F8?=) Hi Marcus. > long ago we decided against supporting it in the array functions. Ok, thanks. Could I ask what the reasons were (Alternatively get a pointer to the discussion)? Regards, Terje > best regards > marcus > > Wednesday, September 13, 2006, 8:39:57 AM, you wrote: > > > Hi all. > > > (Again, I've searched the archives, but haven't found anything on this one) > > The ArrayAccess interface allows one to essentially overload the index > > operator "[]" [1], which is nice, as it makes it possible to implement > > things like type-checked associative arrays, variants, tuples, etc. However, > > you can't use it with any of the built-in array functions (such as count(), > > or the array_*-functions), which means you have to either: > > > 1. Have something like an "as_array()" member function, returning a > > reference to the embedded array, and call this every time you need to call > > one of these functions, or: > > > 2. Implement the functions as member functions on the object. > > > Both of these solutions are rather inelegant, and in particular, 2. leads to > > unnecessary code bloat, and both gives a different calling convention > > compared to ordinary arrays, which can surely confuse readers of the code. > > > My question is: Has it been considered changing the standard library > > functions that take an array as a parameter, to be able to take an object > > implementing ArrayAccess/IteratorAggregate, also? Would it perhaps be a very > > large change? That would be understandable, given that it could mean the > > library having to be able to call into user code (the object being passed). > > However, this is done elsewhere, too, such as foreach(). > > > I know the inability to return a reference is well known. However, has there > > come to a consensus about how to solve it (or if)? It tends to trip up code > > using these "arrays" a lot... Sometimes, you get no change in the array, as > > it turns out it operated on a copy of an element, rather than the built-in > > array. > > > Regards, > > > Terje > > > [1] Since ArrayAccess essentially means overloading the index operator, I'm > > wondering how this have gone through, since some members of the development > > team (Andi?) appears to have very strong feelings against operator > > overloading...?