list() fails to unpack yielded ArrayAccess object

 [2013-11-07 04:39 UTC] stoffle at gmail dot com

Description:
------------
Using list() to unpack the elements of an object (that implements ArrayAccess) provided via Generator::send() unpacks to NULL values.

This issue occurs both with SPL objects that implement ArrayAccess (as in the example) and user-land objects. It does not affect arrays.

When using a user-land object, offsetGet() is never called.


Workaround:

Keeping a reference to the yielded object inside the generator seems to make list() work as expected (see https://gist.github.com/jmalloc/7348967#file-workaround-php).

Test script:
---------------
<?php
function dumpElement()
{
    list($value) = yield;

    var_dump($value);
};

$fixedArray = new SplFixedArray(1);
$fixedArray[0] = 'the element';

$generator = dumpElement();
$generator->send($fixedArray);


Expected result:
----------------
string(11) "the element"


Actual result:
--------------
NULL