# Trait HttpSoft\Message\ResponseTrait

Trait implementing the methods defined in Psr\Http\Message\ResponseInterface.

Source code on GitHub.

# Public methods

See the original detailed description of the methods in the Psr\Http\Message\ResponseInterface.

All other methods with descriptions are in the used trait (HttpSoft\Message\MessageTrait).

Setters prefixed with with they are immutable and return a new instance of the class (using HttpSoft\Message\ResponseTrait) with the changed data.

# getStatusCode

Returns the response status code.

public function getStatusCode(): int;

Example of returned values: 200, 301, 404, 500.

# getReasonPhrase

Returns the response reason phrase associated with the status code.

public function getReasonPhrase(): string;

Example of returned values: 'OK', 'Moved Permanently', 'Not Found', 'Internal Server Error'.

# withStatus

Returns a new instance with the specified status code and, optionally, reason phrase.

 * @param int $code
 * @param string $reasonPhrase
 * @return static
public function withStatus($code, $reasonPhrase = ''): ResponseInterface;

If the reason phrase is not specified, the phrase that corresponds to the default status code will be used.

If invalid specified status code or reason phrase, the \InvalidArgumentException exception will be thrown.

$response->getStatusCode(); // 200
$response->getReasonPhrase(); // 'OK'

$newResponse = $response->withStatus(404);
$newResponse->getStatusCode(); // 404
$newResponse->getReasonPhrase(); // 'Not Found'

$newResponse = $response->withStatus(404, 'Custom Phrase');
$newResponse->getStatusCode(); // 404
$newResponse->getReasonPhrase(); // 'Custom Phrase'

$response->withStatus(99);  // throws InvalidArgumentException
$response->withStatus(600);  // throws InvalidArgumentException
$response->withStatus('Not int');  // throws InvalidArgumentException
$response->withStatus(200, ['Not string']);  // throws InvalidArgumentException

For more information about status code and reason phrase, see here and here.