Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61200 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67644 invoked from network); 13 Jul 2012 14:17:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2012 14:17:04 -0000 Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.170 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.160.170 mail-gh0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:33144] helo=mail-gh0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/47-17670-EDD20005 for ; Fri, 13 Jul 2012 10:17:03 -0400 Received: by ghbg2 with SMTP id g2so4248343ghb.29 for ; Fri, 13 Jul 2012 07:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=G5zUs9cLAnsJ7ICNo+Jek3HYGxrLyE/EvdpSrOXF11E=; b=rvRBfPI2xuF+s4YsWOJr3mg5IkX5Il0z4zWAc0+elfbm6GYmEhCleqrcy03jIeqyE0 zjA5ozneGVPAvMWRLA4ut4ThOA/mH26ihaQ7rL6U4Kxiu3nx6mG1osfMqvTtGb3d4Zqm x6CZNjkycGW69ep2qwIGWcpH9SP7IgvXV+yDOfagCTOGb39VybzOF6A4k2Qc0JL7jrhM FVO8GRtZXK8qF1M6qXlJBAhVZcOA99DGYbJJdTNQvV9pQT12L9Loq0H/lDJokT8gms18 jAPX3qhJpn8zTto3eSG5+Yc/IJINqcvkhEVNxkvZhTbbo7KODG4Es164rIiMY0GyApQc 81vA== Received: by 10.50.159.135 with SMTP id xc7mr1144813igb.9.1342189019660; Fri, 13 Jul 2012 07:16:59 -0700 (PDT) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.64.23.74 with HTTP; Fri, 13 Jul 2012 07:16:17 -0700 (PDT) In-Reply-To: <36.A6.17670.8E820005@pb1.pair.com> References: <1342050547.1456.33.camel@guybrush> <4FFF6C9C.2080802@gmail.com> <36.A6.17670.8E820005@pb1.pair.com> Date: Fri, 13 Jul 2012 16:16:17 +0200 X-Google-Sender-Auth: I3KgKe6v2NSkQ5j8cLOLMW8mWOg Message-ID: To: "Matthew Weier O'Phinney" Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Internal iteration API From: jpauli@php.net (jpauli) On Fri, Jul 13, 2012 at 3:55 PM, Matthew Weier O'Phinney wrote: > On 2012-07-13, David Muir wrote: >> On 13/07/12 01:04, Matthew Weier O'Phinney wrote: >> > On 2012-07-12, Sara Golemon wrote: >> > > --e89a8f235453d7a80104c4975c55 >> > > On Wed, Jul 11, 2012 at 5:39 PM, Anthony Ferrara wrote: >> > > > One thing to keep in mind when doing this is to think about consistency. >> > > > I think that's a huge point not to be taken lightly. For that reason, I >> > > > think that this API should not be used for any of the array_* functions. >> > > > Meaning that array_sum(), etc should all take arrays only. >> > > > >> > > > Then, other non-array functions (such as str_replace, etc) can be modified >> > > > to use this new method. >> > > > >> > > > Just my $0.02 anyway... >> > > > >> > > Sounds like everyone agrees the API is useful, just question marks over >> > > which existing methods should profit by it. >> > > >> > > To add my $0.02, it'd be nice to work in a zend_parse_parameters() type for >> > > this. Keep extension code clean and ensures any temporary iterators get >> > > destructed. >> > Another note: if this comes to fruition, since arrays and traversable objects >> > would in many cases be interchangeable, it would be nice to have a type-hint for >> > "array-like" behavior: >> > >> > function doSomething (ArrayLike $options) { ... } >> > >> > A better name could likely be used, but you get the idea. >> >> What about extending the array typehint include ArrayAccess, and extend >> the Traversable typehint to include arrays? > > This would work for Traversable, as that interface does not define any methods, > and the only use case would be for iteration. This would answer most use > cases/issues I've had (need either an array or Traversable in order to iterate). > > For arrays, however, it's a bit harder, as the reason for typehinting on array > may not be solely access of members, but _also_ iteration. As such, extending > the array typehint to include ArrayAccess could lead to issues when the object > implementing ArrayAccess does not also implement Traversable. I don't think this > would work at all semantically. Yep, today we have : - arrays - Object implementing ArrayAccess - Objects implementing Traversable (Iterator) - array_****() functions not working with ArrayAccess' objects - Iterator API not working with arrays (ArrayIterator needed) - ... I forget things There sure is something to do with that to make a consistent API. So what would be the right answer to make all those ideas join in a sane way everybody agree with ? I got no clue, but I think we should answer this Q for 5.5 Cheers, Julien.P