Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112603 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25212 invoked from network); 22 Dec 2020 21:32:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Dec 2020 21:32:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3E9E71804D1 for ; Tue, 22 Dec 2020 13:05:02 -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=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) (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, 22 Dec 2020 13:05:01 -0800 (PST) Received: by mail-io1-f54.google.com with SMTP id y5so13224110iow.5 for ; Tue, 22 Dec 2020 13:05:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=8KX0DTyNwo3GPk/UnN6oPr9zdJE9fr5aAeWW8CTxkTs=; b=IFDHCvAQvJ/LMaJ23BVDOXEGHtz9SPc/tYULTuO7kn8te0Zaa7yeZZAQR8ZS078l0c rM909aRuVtnf37DNrmV2RoHkIS2Jn0ZX/3g1MIrk8u+2Aqjdg+H/y6AhZ6dF/fHfE35x nrt/Br3CYxhmKUrDRn5UI+Kt3MEq+xY9b2xlI= 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=8KX0DTyNwo3GPk/UnN6oPr9zdJE9fr5aAeWW8CTxkTs=; b=AOVGCWn+scolqGlTvsVhXPkSpR6WjDZDwD1zuoj5mDkopEARHGaHxAi4IoEjBBFUE4 h78+3yxeOFxuUxtWg0DuxYfYfLwWi0xmMyD83x4NkJ069S0ThN0wwUon4n5tiut+qhZ/ tCqKkDMm6UCWWmomG4o1VgSR/8WwZMWkDmFQculV3AYrZNyH4cvNRqPCMm3V5lIIklFN VkU9IRPBSK0gIU4rI/1Wl3IKVUjnL7ZcFw/YpHlxmsjbLrKKFZ+CDwnSHYDMr79ykBfx lOmn68/WLJvdaoGgqlbS04JCklk0Pl3Fjd7xVI/QAAEeIIqEC2Ujr3d1rwWy8jhzkyke 5Deg== X-Gm-Message-State: AOAM533j9mHRMyDHnKA1rqAKjNuBlqyEvahJJXowtBcKCWEK6s0uQbvL e7doLw+2PtjC4BO0pMU6j8Ixwwa/Nh8k9CIYiaPFWYt8AklrUQ== X-Google-Smtp-Source: ABdhPJyvphIbnyqMaz0vbwKF77YAPublYU0kBU/+UQgf/DayolbYUHE6XZoYjPzwG8MwL0MlhYrQ29ikaJZUSOlpJ48= X-Received: by 2002:a6b:8e92:: with SMTP id q140mr19511990iod.182.1608671099689; Tue, 22 Dec 2020 13:04:59 -0800 (PST) MIME-Version: 1.0 Reply-To: Levi Morrison Date: Tue, 22 Dec 2020 14:04:49 -0700 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Name for new, efficient array iterator? From: internals@lists.php.net ("Levi Morrison via internals") The existing ArrayIterator has a large API surface. In most cases it will duplicate the input array either out of ease of implementation or as consequence of the API. Given that a significant use case for ArrayIterator is to write generic code for Iterators that also work on arrays, it is a pretty big drawback to always duplicate the array. Theoretically, I'd like to deprecate basically everything on ArrayIterator except the Countable, Iterator interfaces. This is based on the observation that ArrayObject will do basically all of the same stuff in a more obvious way, so we don't need it for ArrayIterator. Internally, they are basically the same class except for the differences in Iterator and IteratorAggregate APIs. Then, in PHP 9.0 we could make this more efficient. ----- However, I don't want to wait that long, and I suspect it would have too much code churn to remove nicely. The alternative is to make a new array iterator class that has a simple API that avoids duplication of the array. I'm not sure what to name it: - Spl\ArrayIterator - It's a bit confusing, especially because technically \ArrayIterator is in the SPL. - ArrayValueIterator - Its name suggests it is only the array's values that are iterated over, and would skip keys. This was suggested simultaneously with ArrayReferenceIterator, which would hold the inner array by reference. In that context the name makes a bit more sense, but I don't know what use cases there are that wouldn't be served by existing ArrayObject/ArrayIterator. - SimpleArrayIterator? - ForwardArrayIterator? This would go along nicely with a ReverseArrayIterator, I guess. Anyone other ideas?