Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110758 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62660 invoked from network); 28 Jun 2020 13:52:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Jun 2020 13:52:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 663751804D3 for ; Sun, 28 Jun 2020 05:41:20 -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-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 ; Sun, 28 Jun 2020 05:41:19 -0700 (PDT) Received: by mail-lj1-f177.google.com with SMTP id h22so7885795lji.9 for ; Sun, 28 Jun 2020 05:41:19 -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=VTGZIM+ZzwoBcFIKGRf6oP51lzQg0/1JEXXIdlUYJP8=; b=UKNj7Xtc4tog0zlFXaG5asl+0YJFHTrt6WSbXVaon1LQRDUa/0TUwIz2B7wRoiyIPS 6r5F+15QnIMHyiuWhqosDIHohyBjnxN5ac3+7iGxh1oi0DlZzLUEPwVNonx3p+p3nGvW KrqZGhEAaqCzoW4Ec4Q7ZAbrQU1eALKcDTDXuSPJxehlO8KlNTOGfe3Q5eLlg+XwK8K1 A+fvhUXqGcR6lXBV+Sz2kxhs9d5bzxUB4V8lkOnlhFtf02sRNhiEU4hOaQmIzC1aIv7H 0RFzvkaG7o+4KYoOb54P/WmbOTNzBjgFMERzI4bUCNGNcbGSh3bpV1dcX3lgXv9Ezdj5 BBEg== 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=VTGZIM+ZzwoBcFIKGRf6oP51lzQg0/1JEXXIdlUYJP8=; b=lDsdgxAWf9xxOf79iAFAq0bOFzoCeZmU10G+B6Q7WvR7fGT9OG9F4um1Vc0DQWtMMj FsA+v3p08/gs76Znb/uqM7a1mZC/94767hquxNIBUeQ4/s79eObGqxejXKSlQX6Iyo5f 4zSXrKcnIHpBdu2dwGVipTtEvSypD654Vu7HZH4N7W163DaFV4mLgDvUpagkWAYBaUKp gdr3ARTOCYTpcHLBf5kIOWumpjeDvJazC1xzdJLrCVWLh/Li53YX1aIgM7a3vY4zv6t2 CwcfnVYTCf6nWqKA8zIIEfX0s5qKrZC+l3MDHcL0nqGIcjYFbuXXNpUIlNm2SWB7s8uU GcrA== X-Gm-Message-State: AOAM5300p5d7inHRr04jYH7JANru1xfgCZz4lpyQiOsArImBqfqiYaei OQKp0GJkqONitICvtfC5wM0hFn9nVbgf0U/cYxo= X-Google-Smtp-Source: ABdhPJwgDYAFTPrn8hEwE2m6O83Eg+cd31QqT16VKMkJSfYquSgb7cvGpKAmYSGaIcd74XmwZkwwh2e07L9mS49UpbE= X-Received: by 2002:a2e:9cd2:: with SMTP id g18mr6322236ljj.81.1593348078390; Sun, 28 Jun 2020 05:41:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 28 Jun 2020 14:41:02 +0200 Message-ID: To: Alex Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000037522905a9244227" Subject: Re: [PHP-DEV] Convert SplFixedArray to Aggregate? From: nikita.ppv@gmail.com (Nikita Popov) --00000000000037522905a9244227 Content-Type: text/plain; charset="UTF-8" On Fri, Jun 26, 2020 at 8:45 AM Alex wrote: > Dear PHP Internals, > > I would like to propose a backwards-incompatible change to > SplFixedArray which fixes the strange and almost certainly unintended > behavior reported in Bug 79404 > (https://bugs.php.net/bug.php?id=79404). > > In short: Because SplFixedArray is an Iterator, and stores its own > iteration state, it cannot be used in nested foreach loops. If you > try, the inner loop will overwrite the iteration position of the outer > loop, so that the outer loop 'thinks' it is finished after the inner > loop finishes. > > To illustrate: > > $spl = SplFixedArray::fromArray([0, 1]); > foreach ($spl as $a) { > foreach ($spl as $b) { > echo "$a $b"; > } > } > > Only prints two lines: > > 0 0 > 0 1 > > The fix is to convert SplFixedArray to an IteratorAggregate, so each > nested foreach loop operates on a different iterator object and thus > nested loops don't interfere with each other. > > Now, it would be possible to do this while still defining key(), > current(), next(), etc. methods on SplFixedArray. However, that would > cause an even more insidious BC break, since these methods would no > longer work as formerly when called in the body of a foreach loop. > Therefore, I think it better to remove them. This may break a few > users' code, but in a way which will be easier for them to debug than > if the old methods were kept but subtly changed in behavior. > > Code to implement this change is here: > https://github.com/php/php-src/pull/5384/files > > Your comments will be appreciated, > Alex Dowad > I agree that we should make this change for PHP 8. The current behavior is pretty clearly a bug, and the practical backwards compatibility impact should be rather limited (and only annoying to work around if you extend SplFixedArray and override Iterator methods). Nikita --00000000000037522905a9244227--