Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61194 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49031 invoked from network); 13 Jul 2012 11:22:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2012 11:22:47 -0000 Authentication-Results: pb1.pair.com header.from=jared.williams1@ntlworld.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jared.williams1@ntlworld.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ntlworld.com designates 81.103.221.49 as permitted sender) X-PHP-List-Original-Sender: jared.williams1@ntlworld.com X-Host-Fingerprint: 81.103.221.49 mtaout03-winn.ispmail.ntl.com Solaris 10 (beta) Received: from [81.103.221.49] ([81.103.221.49:40163] helo=mtaout03-winn.ispmail.ntl.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/24-17670-40500005 for ; Fri, 13 Jul 2012 07:22:46 -0400 Received: from aamtaout04-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20120713112241.XXGW15330.mtaout03-winn.ispmail.ntl.com@aamtaout04-winn.ispmail.ntl.com>; Fri, 13 Jul 2012 12:22:41 +0100 Received: from p2 ([82.3.17.226]) by aamtaout04-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20120713112241.CFDL16631.aamtaout04-winn.ispmail.ntl.com@p2>; Fri, 13 Jul 2012 12:22:41 +0100 To: "'Nikita Popov'" , "'PHP internals'" Date: Fri, 13 Jul 2012 12:24:34 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 In-Reply-To: Thread-Index: Ac1fsw+nF17o+pWuSx+UDCqv9vfoVwBNk/eA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325 Message-ID: <20120713112241.CFDL16631.aamtaout04-winn.ispmail.ntl.com@p2> X-Cloudmark-Analysis: v=1.1 cv=GaEGOwq9FwezmTggA+b6yC6zDZF2HYaK6RN/tSqdnVA= c=1 sm=0 a=fnwvot8Qg0AA:10 a=uObrxnre4hsA:10 a=oHf_AeXmDeQA:10 a=kj9zAlcOel0A:10 a=pGLkceISAAAA:8 a=YcIQ0WljnSPDt4UYnqgA:9 a=CjuIK1q_8ugA:10 a=MSl-tDqOz04A:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Subject: RE: [PHP-DEV] Internal iteration API From: jared.williams1@ntlworld.com ("Jared Williams") References: > -----Original Message----- > From: Nikita Popov [mailto:nikita.ppv@gmail.com] > Sent: 11 July 2012 23:17 > To: PHP internals > Subject: [PHP-DEV] Internal iteration API > > 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 > I presume this would work with list() too? function *f() { yield 'a'; yield 'b'; } list($a, $b) = f(); Jared