Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110681 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16579 invoked from network); 19 Jun 2020 11:46:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Jun 2020 11:46:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EED341804A8 for ; Fri, 19 Jun 2020 03:33:07 -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-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) (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 ; Fri, 19 Jun 2020 03:33:07 -0700 (PDT) Received: by mail-lf1-f68.google.com with SMTP id d7so5241576lfi.12 for ; Fri, 19 Jun 2020 03:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=DWjHldlD+E2P15CZI1yS4QXxSzHNX+Za333+2aVIpHE=; b=tGKYZtwUTiLK1rumVj+zTXYELZxwWZUT6qeoE2O1i2YwtRTWAaX6+VUqldE52b8f3w LWJ/YJsWx4ls/j+9eOXaVGi6iWkjk0vbWD+Pus/foCe2ut8snUYcADoIXHXMeUImfmSQ u//1aylV55EuOmPNarWHv/NMc4PKtOwQv03oDaKG2I9IIcVZffHfrRobLbCbUWaELGSc j0LrPB86vPh5G4po1tZ5hnYFGEUjRQvCUb9058bjjc66jVgv/O/RHrBPsUfpoRz/h4n3 Mx7Snq3SGKh76Qp2WIbhaY30glF8thwcxdSNoXcpajFaTdNRPMxzw5J0dQnpjdcZr3vS IxAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=DWjHldlD+E2P15CZI1yS4QXxSzHNX+Za333+2aVIpHE=; b=JKRueXy1ZpPaSyzQ+Nml1uyDkrzcSHRAkrGK8PmQjckEzxGz3XYVajoeQhVo3BqxtC gIEdooFlyOYKtCHBlZ9VZkMXsv7AScz0kLJidlWTyM9SD86hCfXvIu5m+cislC6cMcDU dDTZKaeLIF7rc/9a725ex7Py3hhwXa1ro2WnQh9n8kD11gNEruwqBHinbjuZSza3haD3 sxWhp651j09LKJaqhlvAFUiSptRAw37+/REVPIhAzYtamhacBqYIaJguqJ7+ttfGhojw rGQbNbhfnl22Mv+zUf7yQEJy4zWEO7nqjs81H2tHBBEaVpf+QPHBAC69DT9sakqw1eLJ 2ibw== X-Gm-Message-State: AOAM530L27umEGqxMJ9CpqJW9h9v+DEH5IuSvVdYPw9PlvESjTozQHcU xvpjg/YImd/lnUzj7RhUSFtaa04Dz/004Rta3hU0V5ftz4w= X-Google-Smtp-Source: ABdhPJzTqpCQGmsrEqKeOb0GSfgkzNBqbwG/2MlNwZjUz+QrH6X6RLYuX7DCL5KAO336/NvJ9ZOZZqZaFBatPIt7Xi8= X-Received: by 2002:a05:6512:686:: with SMTP id t6mr1636688lfe.154.1592562783428; Fri, 19 Jun 2020 03:33:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 19 Jun 2020 12:32:47 +0200 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000fd25c705a86d6aa8" Subject: Re: Making all Traversables an Iterator or IteratorAggregate From: nikita.ppv@gmail.com (Nikita Popov) --000000000000fd25c705a86d6aa8 Content-Type: text/plain; charset="UTF-8" On Tue, Jun 9, 2020 at 3:33 PM Nikita Popov wrote: > On Tue, May 12, 2020 at 10:26 AM Nikita Popov > wrote: > >> On Wed, Mar 11, 2020 at 10:50 AM Nikita Popov >> wrote: >> >>> 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. >>> >> >> This should have said: "This makes them usable in foreach(), 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. >>> >> >> Does anyone have thoughts on this change? Mostly this is a feature for >> extensions, but also user-visible in that a bunch of classes will switch >> from being Traversable to being IteratorAggregate. >> >> We may also want to convert some existing Iterators to >> IteratorAggregates. For example SplFixedArray currently implements >> Iterator, which means that it's not possible to have nested loops over >> SplFixedArray. We could now easily fix this by switching it to use >> IteratorAggregate, which will allow multiple parallel iterators to work on >> the same array. Of course, there is BC break potential in such a change. >> >> There's some bikeshed potential here regarding the class name. I picked >> "InternalIterator" as an iterator for internal classes, but "internal >> iteration" is also a technical term (the opposite of "external iteration"), >> so maybe that name isn't ideal. >> > > Unfortunately this bikeshed remains unpainted... The proposed names were: > > 1. InternalIterator > 2. ZendIterator > 3. IteratorForExtensionClassImplementations > 4. EngineIterator > > I'm somewhat partial to the third option, with a less verbose name: > IteratorForExtensions. > I went ahead and changed the implementation to use IteratorForExtensions. Is anyone overly unhappy with that one? @Michal: "ExtensionsIterator" to me sounds like an iterator that iterates over extensions. Regards, Nikita --000000000000fd25c705a86d6aa8--