Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110451 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73237 invoked from network); 9 Jun 2020 16:09:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jun 2020 16:09:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ECD03180088 for ; Tue, 9 Jun 2020 07:52:49 -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-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) (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 ; Tue, 9 Jun 2020 07:52:49 -0700 (PDT) Received: by mail-oi1-f194.google.com with SMTP id i74so19004451oib.0 for ; Tue, 09 Jun 2020 07:52:49 -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 :cc; bh=8/ECr1TanAHrVvp2yinSBNsrKuBWD9lMgUofs0/122s=; b=lupingNspvf/fPL7ctxt46Oy1lILu+CgiUu3ekgsx8D5/JIRXRRkprXTMu2kzFuvVU e+5ij4r5caz25VmN/FFQt6WmgXcKGUJoVjw4Hql8CqG45r0hMzAlpSIgvs4DJan0Tj9n IU86kFDoN/a17iZsseJGvKoJH95BKwL9+l8kpUXSyOYeyR+DrX7vvGWj6SNto/dj8FYQ apR3xE8ZVVaLKpUGOdLIF2lbzpR2m878F3h+ObrbsiQGGfiGWfwJicXpBW9xUd3gyIph pnImgy5zYePoODgDsMkgBKM5INx8beTxFW7haGBSBKkU2EzLdGbzw/zDnkVphmr2R03E 0RgQ== 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:cc; bh=8/ECr1TanAHrVvp2yinSBNsrKuBWD9lMgUofs0/122s=; b=i2IA3oPHK5MeLHYOnlt2IB5WaJYfuP2WWJVFFJLAudvNefIJUrRyZe72ah4KjVdrmk kL/n9473E5M9P2JlI9ZptkflUcIhFkD1xl0Uf+ZLs8tPHZd4WchBgBGqe1+5o+QU7x/O HphQmlBIisV6+cRGm9taxuIw79Xt0VFYN3KJ4fZ0lv7winyIR8TOBPD8CKLNTD4ZDKNV FQt+r+qvOGA5NTzeA/+454WK6lxNASvVpG1RwZNyN18sj4xIEF34o9V/5nUi6OmAvlVs nbvfwNLWprlej7Mnj9SkelT6z6TDP2ScYqa2JX48c7z5iRN9rnnCKvNNwkGdctKs188g GtCQ== X-Gm-Message-State: AOAM533d9mLeGmfosCJLWe4eBPFltt9gwZvnA6MF4euHsR5ygIqcsxQd EcAIAGW1VkoNaNwelWRV9N3NbRsChV6M/8G9TfE= X-Google-Smtp-Source: ABdhPJxRk1eoyJcOYGb6ELrM9BS8UFY/kcpPEmbc3sfBUMq9Q4ONtT1seJasYTD9Z/nwFc+XPRowRkem2ylp4lJouBU= X-Received: by 2002:aca:d956:: with SMTP id q83mr3613617oig.78.1591714368744; Tue, 09 Jun 2020 07:52:48 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 9 Jun 2020 16:52:36 +0200 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000088704705a7a7e10c" Subject: Re: [PHP-DEV] Re: Making all Traversables an Iterator or IteratorAggregate From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --00000000000088704705a7a7e10c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable wt., 9 cze 2020, 15:33 u=C5=BCytkownik Nikita Popov napisa=C5=82: > 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 base= d > >> 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 i= s > >> 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() =3D=3D 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 switc= h > > 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 th= at > > 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. > ExtensionsIterator?? BR, Micha=C5=82 > --00000000000088704705a7a7e10c--