When sending an ajax response in the zend framework what is the benefit of using a Zend_Controller_Request_Http object and setting the body and then sending the response as opposed to a simple echo statement.
For example:
$response->setBody('content');
//somewhere later in the application
$response->sendResponse();
versus
echo 'content';
Using Response object instead of direct output is crucial for good application design.
For example, consider situation where you will want to introduce some sort of post-processing to your output, may be sign it with cert:
you can merely attach listener at some point in your application and all you care about is Response object, no need to think how to catch output echoed somewhere in application
There is actually a lot of reason to use it and little to no reasons not to.
Most obvious is that you can attach or change headers at any point in your application.
Most important is that it gives you flexibility in how you can work with output.
Note:
I want to make clarification for later viewers: there is no point to set and immediately send Response object content, it is usually carried throughout the application and call to sendResponse() is the one of the latest actions in request life cycle.