php8.5
Home/ Manual/ yaf / yaf_response_abstract/ Yaf_Response_Abstract::__construct

Yaf_Response_Abstract::__construct

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Construct a response

Description

Yaf_Response_Abstract::__construct()

Construct a response object. The constructor takes no arguments; the concrete subclasses like Yaf_Response_Http and Yaf_Response_Cli initialize their own defaults (an HTTP response starts with the 200 response code, for example).

Note

Usually a response object does not need to be constructed manually: Yaf_Dispatcher::getResponse returns the one created by the dispatcher.

Parameters Parameters

Return Values

No value is returned.

Examples

Yaf_Response_Abstract::__construct example

php
<?php
/* usually there is no need to construct a response manually:
 * the dispatcher creates one and hands it out */
$response = Yaf_Dispatcher::getInstance()->getResponse();

/* constructing directly is mostly useful in tests */
$response = new Yaf_Response_Http();
$response->setBody("Hello World");

echo $response;
?>

The above example will output something similar to:

output
Hello World

See Also

  • Yaf_Dispatcher::getResponse
  • Yaf_Response_Abstract::response

Source: reference/yaf/yaf_response_abstract/construct.xml · from the official PHP manual (php/doc-en)