Andrew Carter has written up a new post about PSR-7 objects (the PHP-FIG defined standard for handling requests and responses in PHP applications) and how the objects themselves are immutable.
What’s happening [in the provided example] is that the Zend Expressive framework is rendering the error page to the same object that you wrote your message to. Whilst the actual message object itself is immutable, the body stream that it references is not. Even when this object is cloned or “modified” (to become a new object) it will still use the same stream.
He explains a bit about what this means in a more practical sense and why the PSR-7 standard and why this happens (as defined after much discussion). Then he gets into a more recent debate happening in the PHP-FIG about PSR-7 middleware and the proposal for a standard structure in its creation. He points to some of the thoughts from Anthony Ferrara on the topic and an example from Woody Gilk showing an exception handler and how having the stream always appending content is a bad thing in that particular case.