zendframework / zend-diactoros

PSR-7 HTTP Message implementation
BSD 3-Clause "New" or "Revised" License
1.55k stars 152 forks source link

Generators are not supported for JSON responses. #365

Open nbish11 opened 5 years ago

nbish11 commented 5 years ago

Code to reproduce the issue

function getSomeData(): Generator {
    yield 1 => 'One';
    yield 2 => 'Two';
    yield 3 => 'Three';
}

$data = getSomeData();
$json = new Zend\Diactoros\Response\JsonResponse($data);

Expected results

Response should consume the generator and treat it as if a normal PHP array was passed in:

$data = [
    1 => 'One',
    2 => 'Two',
    3 => 'Three'
];

$json = new Zend\Diactoros\Response\JsonResponse($data);

Actual results

An error is thrown instead: "Trying to clone an uncloneable object of class Generator..."

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-diactoros; a new issue has been opened at https://github.com/laminas/laminas-diactoros/issues/5.