phasync
Response / __construct

Method

Response::__construct

Creates a response.

Description#

public Response::__construct(
    int $statusCode = 200,
    array $headers = [],
    ?StreamInterface $body = null,
    string $protocolVersion = '1.1',
    ?string $reasonPhrase = null
)

Parameters#

$statusCode int = 200
HTTP status code
$headers array = []
Array of header names => values
$body ?StreamInterface = null
Body; null is an empty stream
$protocolVersion string = '1.1'
The HTTP protocol version, typically "1.1" or "1.0"
$reasonPhrase ?string = null
The HTTP reason phrase; null or '' gives the standard phrase for $statusCode, or '' when there is none

Errors / Exceptions#

ExceptionWhen
InvalidArgumentExceptionFor a status code outside 100-599, a reason phrase with control characters, or an invalid header (a value that is not a string is rejected)