Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108772 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22679 invoked from network); 26 Feb 2020 18:34:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Feb 2020 18:34:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4A7501804F4 for ; Wed, 26 Feb 2020 08:52:10 -0800 (PST) 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-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (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, 26 Feb 2020 08:52:09 -0800 (PST) Received: by mail-io1-f43.google.com with SMTP id z1so4071473iom.9 for ; Wed, 26 Feb 2020 08:52:09 -0800 (PST) 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=sORcm9jzbibHGSBBaRi2OD+cEdJNU49MoAHLuVhOU90=; b=fOMNhf9QJMfAjnrIlOvdgGPfqL8MT7Ti3ENqnvZsXwzRh6EB4GMUn11FNjBXZ/YA98 93Ouo57grDASCzTklpdwAti2wTz/nOwV+uRUVYxDVD0MXiQ36PpdawVLymmEaeW0VVV4 B3tW/dwZflC2aVDUZi7Eg8fdxwkASDBQsOG/JdEr1dUUvZUxs5zNgv6MajCcrNTSCOHR TfjUBb2lIE/9lpeUZZpppAuHbQJ7hNBZcn9SK3+yz+gxwXwMa+rG7bop8yixswAyO6wh Rjm3qARBwbYE8M+P9H4vhnIIAqMTlW4N+zisJvozcoduFRLXhOGQ4jU+PbE8dli8D9tU 7mBQ== 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=sORcm9jzbibHGSBBaRi2OD+cEdJNU49MoAHLuVhOU90=; b=hPcH/JSdYfluQhXDGFktAA8lbabVwJwISut/eEWLU5dX4/jVXd3uY2k0EJaO37/WSb clKWmthMQvfNRHJW3fR6QDBEkt9daw5FDs61T+JLO7yZ6dUCvb5DOKWtoESaYMowFna0 VLUxUEIXlbUbq91OFY4LLFYPNmNvzK9G4c1+7JXJpmzm3dnOXwbfHabylXx4iQOTsTGe inWQviXZoxWCRqz8ZiBT6fzg37mkSXuhI+lh94aZIaKX7Bb/u5IJi3zNfD5666SNEtoS YewimtPJysmlFLF2kC/9ZWg6QFjAXbKqUwBY3IzVwvWVaEZ47cVBDTA5y2afA7HSedwh Ax3w== X-Gm-Message-State: APjAAAW7n20bzCWO0vFp1B61JYaZ4dnybdHdBX2Y/g+1zufumGGySSEw PtTcrdCMncRgdhMaKbbcTiqW/kYREfODmObHaOlRrUu6 X-Google-Smtp-Source: APXvYqzr+1JAzRSr5Lh0kql2Ls0zhIXVmNvKb+49XGs/hz/wpxg+DkXkl6Z5ZrKPoW81LfIzaBxgAEPxO+0SNLA8Yqk= X-Received: by 2002:a5d:8448:: with SMTP id w8mr5699951ior.161.1582735927648; Wed, 26 Feb 2020 08:52:07 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 26 Feb 2020 16:51:56 +0000 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000bda648059f7d6c7f" Subject: Re: [PHP-DEV] Support rewinding of generators From: rowan.collins@gmail.com (Rowan Tommins) --000000000000bda648059f7d6c7f Content-Type: text/plain; charset="UTF-8" On Wed, 26 Feb 2020 at 15:23, Nikita Popov wrote: > Point of order: foreach() always rewinds the array / Iterator it gets. The > code does work correctly under the proposed scheme. > Ah, I'd missed that, sorry; that makes the entire first half of my e-mail irrelevant. :) The proposed behaviour is actually closer to current behaviour than I thought, because the initial code before the first yield actually runs when you first rewind the iterator: function foo() { echo 'Begin'; yield 42; } $f = foo(); // Doesn't echo yet $f->rewind(); // Now echoes 'Begin' $f2 = foo(); foreach ( $f2 as $x ) { // echoes 'Begin' before first loop echo $x; } Just to check, would the proposed behaviour still special-case a generator which hasn't been progressed? $f = foo(); $f->rewind(); // echoes 'Begin' $f->rewind(); // this would still do nothing? $f->next(); $f->rewind(); // this currently throws an error, and would echo 'Begin' again? Regards, -- Rowan Tommins [IMSoP] --000000000000bda648059f7d6c7f--