Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61144 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84302 invoked from network); 11 Jul 2012 22:17:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2012 22:17:30 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:49539] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/71-09688-87BFDFF4 for ; Wed, 11 Jul 2012 18:17:29 -0400 Received: by lbgc1 with SMTP id c1so2679274lbg.29 for ; Wed, 11 Jul 2012 15:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=JGoM9EzzQdYC+dDh6ZACuQP/212hddLPrR65AxphHAw=; b=N87tDFti40cDBSw8T5WAFuRnYxtYGr32NkjjBEW+NjcFi8UV6PxS/ozBxGcKvd9m6/ ikrFQZfaQUQm3rmjNSys8mklN7ZUrBDASinlwIdNhggFALEeNJ8lQKy6F8k5B5RaASLK pElkqwX5t3Uc4ppy5TBNlmXTn4XhpJlpqq5NW42EXE2jhriCXoNWELq48JrqG22w+xHZ czBzH3m5ZiXw6r583QaePqfQ3IL6Nlp3NKYkCtgfU87RjocP9MfxtASYn9+er7imSh5u WQ4HGWJAPbbeEtO0Dcx9oNMl847Gn5icQGm0eead3t9Et4dyIYtuq2vudChjZjP2yOoW YD7w== MIME-Version: 1.0 Received: by 10.112.104.100 with SMTP id gd4mr3217798lbb.24.1342045045742; Wed, 11 Jul 2012 15:17:25 -0700 (PDT) Received: by 10.152.114.70 with HTTP; Wed, 11 Jul 2012 15:17:25 -0700 (PDT) Date: Thu, 12 Jul 2012 00:17:25 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Internal iteration API From: nikita.ppv@gmail.com (Nikita Popov) 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