PHP Slim, issue when returning a response
Solution:
Solved! Must be written like this:
$response->getBody()->write(json_encode($person));
return $response;
Answer
Solution:
You want:
$response->write()
That method returns the response object. Internally it calls $response->getBody()->write()
Answer
Solution:
According to the Psr\Http\Message\StreamInterface specs, the write()
method looks like this:
/**
* Write data to the stream.
*
* @param string $string The string that is to be written.
* @return int Returns the number of bytes written to the stream.
* @throws \RuntimeException on failure.
*/
public function write($string);
So it doesn't return the instance, it just returns a byte count. I suspect you were relying on getting some kind of fluent interface.
Source