Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61145 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87444 invoked from network); 11 Jul 2012 23:05:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2012 23:05:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.213.46 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.213.46 mail-yw0-f46.google.com Received: from [209.85.213.46] ([209.85.213.46:45677] helo=mail-yw0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 77/F1-09688-E960EFF4 for ; Wed, 11 Jul 2012 19:05:02 -0400 Received: by yhmm54 with SMTP id m54so2112561yhm.19 for ; Wed, 11 Jul 2012 16:04:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:x-originating-ip:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=Ddk+tROvBkVK8iDjLDcXqlR6u+OmXxfupkThteQs6HY=; b=hCaE7R+SItRsHbArnBiSiSddzIq60bb0rsM21VFgoDVlTXd46N7JToDFT3eQhtPSIe T4CxtPgv/9e94+Gvin5gauY8O7PE0y/i3FJEI28lp5bCU6Rhh7n8I+rAGLW671qJPx6i ErXcsV8c1xR2MyH6Qai1UIOTINLoaXXMHSFg0H4a1z/W35lWEWlNMekJRLAwx4ZSdyin lao/hYpywAVKClyrBTc56mxrFpvHQcsFiveyICLKA7oVgiagPev9SxkE6ccT3sNfJRaq cLCyExqBoxZ3N8KXRYGgFMV5rysBTTTkcbl/I5lW9KIOvW3rlWcGQtDsWKy2ZxoNDPjP zwlw== MIME-Version: 1.0 Received: by 10.42.155.200 with SMTP id v8mr26156569icw.12.1342047899093; Wed, 11 Jul 2012 16:04:59 -0700 (PDT) Sender: php@golemon.com Received: by 10.64.24.242 with HTTP; Wed, 11 Jul 2012 16:04:59 -0700 (PDT) X-Originating-IP: [2620:0:1cfe:28:c4d4:5113:14d8:4b58] In-Reply-To: References: Date: Wed, 11 Jul 2012 16:04:59 -0700 X-Google-Sender-Auth: Epqcp4FgjgKEKw_K3yP3YJi4yb4 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary=90e6ba1efc164c0aa904c495e00c X-Gm-Message-State: ALoCoQk1pH9NPcpmRJKnE7DRyq5Zz/0Z5lggt50f44bPeoUnWExLRTpiIX4rwUiD2w/7JJFnUmbR Subject: Re: [PHP-DEV] Internal iteration API From: pollita@php.net (Sara Golemon) --90e6ba1efc164c0aa904c495e00c Content-Type: text/plain; charset=ISO-8859-1 Love the idea. +1 On Wed, Jul 11, 2012 at 3:17 PM, Nikita Popov wrote: > Hi internals! > > Currently PHP does not have an internal iteration API that supports > both arrays and Traversable objects. Because of that it is currently > not really possible to write functions (or language features) that > work on arbitrary traversables. That's probably also the reason why > function like array_sum() currently work only on arrays and arrays > only. > > So I'd really like to have such an API. One idea for an implementation > would be this: > * Create a zend_create_iterator_from_zval() function, which returns a > zend_object_iterator > * For arrays and plain objects this would create a thin wrapper > around the zend_hash_* iteration functions > * For objects defining get_iterator this would just return the > object_iterator that get_iterator returned > * Usage: > > zend_object_iterator *iter = zend_create_iterator_from_zval(zval); > if (iter->rewind) iter->rewind(iter); > while (iter->valid(iter)) { > zval **value; > iter->get_current_data(iter, &value); > // do something > iter->move_forward(iter); > } > iter->dtor(iter); > > I like this approach because it reuses the existing > zend_object_iterator API. But I see that this is rather an abuse than > a use :) > > Thoughts? > > Nikita > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --90e6ba1efc164c0aa904c495e00c--