Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110731 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34051 invoked from network); 26 Jun 2020 07:56:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Jun 2020 07:56:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2F0491804CE for ; Thu, 25 Jun 2020 23:44:40 -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, 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-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 ; Thu, 25 Jun 2020 23:44:39 -0700 (PDT) Received: by mail-lj1-f173.google.com with SMTP id 9so9159101ljv.5 for ; Thu, 25 Jun 2020 23:44:39 -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=KKXHHttX9o1PKMAjYK9lWbZCcakr5kl03XygeyWUEVM=; b=ibdnJV20nhEZGSfNfXV403gCwiAvI5lT8hZOYgu7opzGBtFdy+1L0s19XoKs8nc7mO 8ohe5V4xGZTMmzR2ETXQMMntjnvZYUZc8SKF1tyJLBjlDn3qxazdlDCdcwvpmlkaGLgl 931trXITDH0pVMClAzQYk/o93fJCPOAu8EnmxCqsMg3ba1GbMDTJ2Bdvxvtkz/HwwolA uLSr5cpft7+5e5PhXBtIWgLrY+4cBiyeHcImcOMrbC3aht1VnT8B00ziqQq8tS5fd06U 5AHO7NRG/z4D/0ik6R/b5p097zB52C2SQwYOkts9973Vh0irs1SZEV3e48s9RC5sGUVg u1Bg== 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=KKXHHttX9o1PKMAjYK9lWbZCcakr5kl03XygeyWUEVM=; b=SYhHADhG4258N9y2hb9BBZhang2GzyjACO42SJXKGlGoSNBFntNirdiZwKTLwEcUS7 Fd/SI8FMKxVZS6gXMtaZd4nk4aGszvt+mV5igJP0nXPywdZ0RvjwWcQDxxnmpRubFhT1 Ex93/DVCPyCg8eAz8aweLGqKCa+jI9kStNZFbSTtTgGAzrG7zdazx+nwY9yHDmvbylxs bp/byCKucnYh8zmNCdKPNzgqoZpUp/SPt1wFcRT4EWTnEo0YwV4W6xgUrFwf+9CC8KGN RB8+YeS/KQHnizVzoO0G++jC1e0KrVyvTkY6bRjcsS5UvSJ0IdWd4rG8yXsNshwtay5B byNA== X-Gm-Message-State: AOAM531sYotHDV35y//wdfXrbtqqZOYeZhVL4JGKC4D7unqTOKC+zbbH dbQrLAx0bqpVJzKFcbpxD8vPt4yboS2mmA8uyY1CijCX0RA= X-Google-Smtp-Source: ABdhPJy0w7Av/EyWb2ACVHfZvmtL/zm3VrFedUQUZCS3PjocoQD1qd9HTSX/MMek6XEcOJhFiu27pHguEeKOwfRh2BQ= X-Received: by 2002:a05:651c:305:: with SMTP id a5mr646238ljp.387.1593153875621; Thu, 25 Jun 2020 23:44:35 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 26 Jun 2020 08:44:19 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Convert SplFixedArray to Aggregate? From: alexinbeijing@gmail.com (Alex) 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