Bug #66041 [Opn->Asn]: list() fails to unpack yielded ArrayAccess object
Edit report at https://bugs.php.net/bug.php?id=66041&edit=1
ID: 66041
Updated by: nikic@php.net
Reported by: stoffle at gmail dot com
Summary: list() fails to unpack yielded ArrayAccess object
-Status: Open
+Status: Assigned
Type: Bug
Package: Scripting Engine problem
Operating System: OS X 10.8.5 - Mountain Lion
PHP Version: 5.5.5
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Verified on master.
Previous Comments:
------------------------------------------------------------------------
[2013-11-07 04:39:23] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66041&edit=1
Thread (3 messages)