> -----Original Message-----
> From: Nikita Popov [mailto:nikita....@gmail.com] 
> Sent: 11 July 2012 23:17
> To: PHP internals
> Subject: [PHP-DEV] Internal iteration API
> 
> Hi internals!
> 
> Currently PHP does not have an internal iteration API that 
> supports both arrays and Traversable objects. Because of that 
> it is currently not really possible to write functions (or 
> language features) that work on arbitrary traversables. 
> That's probably also the reason why function like array_sum() 
> currently work only on arrays and arrays only.
> 
> So I'd really like to have such an API. One idea for an 
> implementation would be this:
>  * Create a zend_create_iterator_from_zval() function, which 
> returns a zend_object_iterator
>  * For arrays and plain objects this would create a thin 
> wrapper around the zend_hash_* iteration functions
>  * For objects defining get_iterator this would just return 
> the object_iterator that get_iterator returned
>  * Usage:
> 
>        zend_object_iterator *iter = 
> zend_create_iterator_from_zval(zval);
>        if (iter->rewind) iter->rewind(iter);
>        while (iter->valid(iter)) {
>            zval **value;
>            iter->get_current_data(iter, &value);
>            // do something
>            iter->move_forward(iter);
>        }
>        iter->dtor(iter);
> 
> I like this approach because it reuses the existing 
> zend_object_iterator API. But I see that this is rather an 
> abuse than a use :)
> 
> Thoughts?
> 
> Nikita
> 

I presume this would work with list() too? 

function *f()
{
    yield 'a';
    yield 'b';
}

list($a, $b) = f();


Jared


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to