|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-06-29 21:59 UTC] gavroche dot bull at gmail dot com
Description:
------------
The yield function in the example below gives a "zend_mm_heap corrupted" error.
Test script:
---------------
function dump($chunk = 500)
{
$m = new MongoClient();
$db = $m->dbname;
$collection = $db->selectCollection('collectionname');
$cursor = $collection->find();
$count = 0;
$output = [];
foreach ($cursor as $doc) {
$doc = array_filter($doc, function($v) { return !is_object($v); });
$output[] = $doc;
$count++;
if ($count === $chunk) {
yield json_encode($output);
$output = [];
$count = 0;
}
}
yield json_encode($output);
}
foreach(dump() as $dump) {
var_dump($dump);
}
Expected result:
----------------
No error.
Actual result:
--------------
zend_mm_heap corrupted
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 01:00:01 2025 UTC |
This works: ------------------------------- function dump($cursor, $chunk = 500) { $count = 0; $output = []; foreach ($cursor as $doc) { $doc = array_filter($doc, function($v) { return !is_object($v); }); $output[] = $doc; $count++; if ($count === $chunk) { yield json_encode($output); $output = []; $count = 0; } } yield json_encode($output); } $m = new MongoClient(); $db = $m->dbname; $collection = $db->selectCollection('collectionname'); $cursor = $collection->find(); foreach(dump($cursor) as $dump) { var_dump($dump); }