On Wed, Jul 15, 2015 at 3:43 PM, Johannes Schlüter <johan...@schlueters.de> 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 Traversable > > as well as arrays; instead of only supporting this for my own functions, > > I've generalised this so that other functions can take advantage of this > as > > well. These are the additions: > > > > 1. A ZPP argument; the "t" (for traversable) argument type has been added > > that checks for either an array or implementation of zend_ce_traversable. > > > > 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 to 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. Julien Pauli