Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Generators are not supported for JSON responses. #365

Open
nbish11 opened this issue Jul 27, 2019 · 1 comment
Open

Generators are not supported for JSON responses. #365

nbish11 opened this issue Jul 27, 2019 · 1 comment

Comments

@nbish11
Copy link

nbish11 commented Jul 27, 2019

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
Copy link
Member

This repository has been closed and moved to laminas/laminas-diactoros; a new issue has been opened at laminas/laminas-diactoros#5.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants