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

From: Date: Sat, 30 Nov 2013 12:43:46 +0000
Subject: Bug #66041 [Asn->Csd]: list() fails to unpack yielded ArrayAccess object
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183027@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: Assigned +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: OS X 10.8.5 - Mountain Lion PHP Version: 5.5.5 Assigned To: nikic Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2013-11-30 10:47:28] nikic@php.net Verified on master. ------------------------------------------------------------------------ [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

« previous php.bugs (#183027) next »