Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87188 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46861 invoked from network); 15 Jul 2015 19:39:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jul 2015 19:39:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.49 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.216.49 mail-vn0-f49.google.com Received: from [209.85.216.49] ([209.85.216.49:37789] helo=mail-vn0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/36-27477-CD6B6A55 for ; Wed, 15 Jul 2015 15:39:09 -0400 Received: by vnav203 with SMTP id v203so5700669vna.4 for ; Wed, 15 Jul 2015 12:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=Q3QBj9LEknhx+Y5y/gYWQv+Z8LVJ/FN2iWp5xj3qvhk=; b=RzMU4p9WWIPy35pqmpzFf7KqwvI+haV6Drkg14AgMhITnjL3HXrvmFfC+hryqylfuL Do70xZuu3UbfEO1YLna1ZrTL0O6XzzdzkoDTMJEjU4Rzo2aT9rBghOMgsGfE1TSATMZK 6el1UFDhn/D49PZdNojVIqPmW3T5YiOXn2zNxgyEGxb+HxhYxkfFfF7bwgcJlJS+BPZF MB3WA2T8X9cLqXMLdDXGXje0KFuBHwdlkZQyDagCXzo6q+EuNiS153IkO7XbzqX3WHq2 ZN6BKaExnDEgPWczIjCz1TKviklmJnjiK7ydmag7EnHgCYwDeFdA4Z6bDWr+O51KzE8K gpXw== MIME-Version: 1.0 X-Received: by 10.52.52.114 with SMTP id s18mr6261957vdo.9.1436989145939; Wed, 15 Jul 2015 12:39:05 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.31.16.68 with HTTP; Wed, 15 Jul 2015 12:39:05 -0700 (PDT) In-Reply-To: References: <1436967838.8300.16.camel@kuechenschabe> Date: Wed, 15 Jul 2015 13:39:05 -0600 X-Google-Sender-Auth: a4J-GyUt_sWPiIxoRDLB2kBaKVg Message-ID: To: Julien Pauli Cc: =?UTF-8?Q?Johannes_Schl=C3=BCter?= , Tjerk Meesters , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Consolidation of Traversable and array operations From: levim@php.net (Levi Morrison) On Wed, Jul 15, 2015 at 8:31 AM, Julien Pauli wrote: > On Wed, Jul 15, 2015 at 3:43 PM, Johannes Schl=C3=BCter > wrote: > >> Hi, >> >> On Wed, 2015-07-15 at 11:28 +0000, Tjerk Meesters wrote: >> > The most notable comment was that it would be nice to support Traversa= ble >> > as well as arrays; instead of only supporting this for my own function= s, >> > I've generalised this so that other functions can take advantage of th= is >> as >> > well. These are the additions: >> > >> > 1. A ZPP argument; the "t" (for traversable) argument type has been ad= ded >> > that checks for either an array or implementation of zend_ce_traversab= le. >> > >> > 2. A generic iteration function, called php_traverse(); it accepts: >> > a. the zval* to iterate over, >> > b. a step-wise function that receives the value and key, and returns= a >> > boolean that determines whether iteration should continue or not, >> > c. a traversal mode (only values, or keys and values), >> > d. a context that's sent to the step-wise function. >> >> I really like this concept to unify by access pattern, hiding the actual >> implementation! >> >> > 3. A concrete implementation of a step-wise iteration function, >> > php_traverse_until, that gets called as part of array_every() and >> > array_some(). >> >> I wonder if we can find a better naming scheme. For some array_ >> functions this will work, others not. This again feeds the "PHP is so >> inconsistent"-trolls. At the moment I'm leaning towards simply using >> every() and some_of() without reference to a type. Or maybe introduce, >> to restart the namespace-debate, php\every(), php\search(), php >> \someOf(), php\product(), etc. and deprecate array_search() etc. >> >> johannes >> >> > Nikic designed "Iter" some time ago, when he finished adding Generators t= o > PHP. > Perhaps some ideas could be taken from it. > https://github.com/nikic/iter > > I suggest writing an RFC and target 8.0, while the deprecations could > target 7.X > > Also, there has been an open subject for ages about how could we uniform > array and Traversable internally, as well as from PHP user land (the main > subject was then to add support for ArrayAccess to every array_***() PHP > function). > > I'm happy this bumps the subject up , as it is quite a hot topic. Do note that the union types RFC would also alleviate some of this pain for user-land functions, since `array | Traversable` would cover the required access pattern. I think this is a superior approach myself, but I may be a bit biased as I am authoring that proposal: https://wiki.php.net/rfc/union_types