Bug #66041 [Opn->Asn]: list() fails to unpack yielded ArrayAccess object

From: Date: Sat, 30 Nov 2013 10:47:29 +0000
Subject: Bug #66041 [Opn->Asn]: list() fails to unpack yielded ArrayAccess object
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183026@lists.php.net to get a copy of this message
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)

« previous php.bugs (#183026) next »