php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66041 list() fails to unpack yielded ArrayAccess object
Submitted: 2013-11-07 04:39 UTC Modified: 2013-11-30 10:47 UTC
From: stoffle at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.5.5 OS: OS X 10.8.5 - Mountain Lion
Private report: No CVE-ID: None
 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-30 10:47 UTC] nikic@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2013-11-30 10:47 UTC] nikic@php.net
Verified on master.
 [2013-11-30 12:43 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9589cae8cb1b13710ca36491f30b569113f9e329
Log: Fixed bug #66041: list() fails to unpack yielded ArrayAccess object
 [2013-11-30 12:43 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2013-12-01 11:32 UTC] ab@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9589cae8cb1b13710ca36491f30b569113f9e329
Log: Fixed bug #66041: list() fails to unpack yielded ArrayAccess object
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC