Open weierophinney opened 4 years ago
function getSomeData(): Generator { yield 1 => 'One'; yield 2 => 'Two'; yield 3 => 'Three'; } $data = getSomeData(); $json = new Zend\Diactoros\Response\JsonResponse($data);
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);
An error is thrown instead: "Trying to clone an uncloneable object of class Generator..."
Originally posted by @nbish11 at https://github.com/zendframework/zend-diactoros/issues/365
JsonResponse expectation for $data is array or value bag object such as stdclass, same as values passed to json_encode().
JsonResponse
$data
json_encode()
phpdoc and documentation needs an update to clarify this expectation.
Code to reproduce the issue
Expected results
Response should consume the generator and treat it as if a normal PHP array was passed in:
Actual results
An error is thrown instead: "Trying to clone an uncloneable object of class Generator..."
Originally posted by @nbish11 at https://github.com/zendframework/zend-diactoros/issues/365