Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45153 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24137 invoked from network); 30 Jul 2009 18:35:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jul 2009 18:35:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 63.205.162.117 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 63.205.162.117 us-mr1.zend.com Linux 2.4/2.6 Received: from [63.205.162.117] ([63.205.162.117:41515] helo=us-mr1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2F/D6-25953-DF7E17A4 for ; Thu, 30 Jul 2009 14:35:42 -0400 Received: from us-gw1.zend.com (us-ex1.zend.net [192.168.16.5]) by us-mr1.zend.com (Postfix) with ESMTP id AAAB5E1248 for ; Thu, 30 Jul 2009 11:23:41 -0700 (PDT) Received: from [192.168.16.202] ([192.168.16.202]) by us-gw1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 30 Jul 2009 11:23:17 -0700 Message-ID: <4A71E4DD.2090005@zend.com> Date: Thu, 30 Jul 2009 11:22:21 -0700 Organization: Zend Technologies User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: Guilherme Blanco CC: =?UTF-8?B?Sm9oYW5uZXMgU2NobMO8dGVy?= , Alexey Zakhlestin , PHP internals References: <1248962475.4159.14.camel@goldfinger.johannes.nop> <1248968847.4159.31.camel@goldfinger.johannes.nop> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 30 Jul 2009 18:23:17.0500 (UTC) FILETIME=[CF2FA3C0:01CA1142] Subject: Re: [PHP-DEV] Supporting ArrayObject in array_* functions From: stas@zend.com (Stanislav Malyshev) Hi! > 1- A class that implements ArrayAccess must be useable everywhere an > "array" is useable; The problem is that many functions dealing with arrays do not make sense with generic object. For others, it may make sense in theory, but not be practical - e.g., suppose you have ArrayAccess object referring to a database field, how easy would be to make shuffle() work on it? How practical would it be? > 2- ArrayAccess needs to be expanded with methods for all the array > functions and ArrayObject needs to implement them; All 70+ of them? That'd be one fat interface. > How would it be achieved? > $coll->sort(); instead of sort($coll); > $coll2 = $coll->reverse(); instead of $coll2 = array_reverse($coll); Note that this also eats up a lot of useful names, and makes you implement functions that you would never use, such as picking a random element or finding difference between arrays. I think all array operations should be divided into following classes: 1. Basic ones, probably ArrayAccess/Iterator interface should be enough 2. Compound ones implemented on top of basic ones (i.e. array_sum is a combination of iteration and +, etc.) 3. Additional operations non-reducible to (1), like shift/unsift or exotic ones like array_change_key_case(). First two classes are easy to handle, the last one should be handled separately on per-case basis. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com