Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108970 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8666 invoked from network); 11 Mar 2020 11:29:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Mar 2020 11:29:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 57F351804DF for ; Wed, 11 Mar 2020 02:50:41 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 11 Mar 2020 02:50:40 -0700 (PDT) Received: by mail-lf1-f48.google.com with SMTP id x22so1129279lff.5 for ; Wed, 11 Mar 2020 02:50:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=YA03sMMM886GJEpKZG0+8CefsryvIJWBxEmpJjvKVPo=; b=VkwJEbKbpYI2VJdK8hsA9ypRiw52NvGzzTYUhdVa/ZTWvR2fgG3Sd6keV6+1sI5VIX 8NlWbj6Sny6yZB0vZ/uA9k81Av2iFngCgp3IAEydLPYNQFCS3Z1DWmtksFdZwaK9RMV8 235rW23qfvpua9YUB5lODpsbnrYjuXADJNmITFTuS/QyFrLPOH3/YhHQIR8DKFWL9erK GgIWwvSTeIB1JYFBJHwyXIin0x+pERQR9KHvqsmLBMoVlYM4L7XgdZEmTz7tdkbtxeG/ xmcP2HW3K5W198OGnNa7+rkLmsL00T7iThKMkeYdtCebwGgKVHkP2PVjn1TFi+3ds9/H gnyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=YA03sMMM886GJEpKZG0+8CefsryvIJWBxEmpJjvKVPo=; b=ckACgoXwjYNgR+nsOSFXcwghz0qG+THpnS683CuqWB9Tt5ssXkAg/3QIb7hPfVXKkV ik4ycHnhosXjfGgJS8rmrDfZbNonfjWSQa3rxrbZ6PuLUL8ItzuQDCbbyYWB1Dl4D+4Z DuyCzNQNmuenx2ZsouEknrnQikMIg6X63x4AW7un05+oscLU2dyLQ615HFvdHoDMRW2L RZWaVOr6z4+SDS6f6Ns4oKS6y0hrIFYGO+DR1IIcLRtNn69N4zUc3Vgbk5QrOaD6qZjH v7PPUmzEnQj1kAtlYSVvR6QDqLYONkHonJnxSdTNi6ZDj3VQyIfI8AQz3mGHqfPFsmI+ K7zw== X-Gm-Message-State: ANhLgQ23VR0/JzR5yXoAkkQFI/HSYjZUETXomfviCJbRdgmWyDofQDUJ kX3FSG4FwkLGVk1rkJJMfrTMvvVb4autCT9JHlWz9SqD26/Jiw== X-Google-Smtp-Source: ADFU+vs9EAj/GA5Z1Gr3sfSVtKEboxMPtRHWMTEnQ6VFJimik/X1z+l6CCqcbe4TPM+G46WZU4I7BV6kfHNQDJ49Wp4= X-Received: by 2002:a05:6512:15e:: with SMTP id m30mr1597233lfo.120.1583920238195; Wed, 11 Mar 2020 02:50:38 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 11 Mar 2020 10:50:22 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000267a0f05a0912b0c" Subject: Making all Traversables an Iterator or IteratorAggregate From: nikita.ppv@gmail.com (Nikita Popov) --000000000000267a0f05a0912b0c Content-Type: text/plain; charset="UTF-8" Hi internals, Userland classes that implement Traversable must do so either through Iterator or IteratorAggregate. The same requirement does not exist for internal classes: They can implement the internal get_iterator mechanism, without exposing either the Iterator or IteratorAggregate APIs. This makes them usable in get_iterator(), but incompatible with any Iterator based APIs. A lot of internal classes do this, because exposing the userland APIs is simply a lot of work. I would like to add a general mechanism to make this simpler: https://github.com/php/php-src/pull/5216 adds a generic "InternalIterator" class, that essentially converts the internal get_iterator interface into a proper Iterator. Internal classes then only need to a) implement the IteratorAggregate interface and b) add a getIterator() method with an implementation looking like this: // WeakMap::getIterator(): Iterator ZEND_METHOD(WeakMap, getIterator) { if (zend_parse_parameters_none() == FAILURE) { return; } zend_create_internal_iterator_zval(return_value, ZEND_THIS); } This allows internal classes to trivially implement IteratorAggregate, and as such allows us to enforce that all Traversables implement Iterator or IteratorAggregate. Regards, Nikita --000000000000267a0f05a0912b0c--