Documentation

Response
in package

Represents an HTTP response

This class models an HTTP response, providing methods to manipulate headers, status codes, and content.

Table of Contents

Methods

exitWithErrorMessage()  : never
Exit with an error message and set HTTP status code to 500 (Internal Server Error)
exitWithMessage()  : never
exitWithStatusCode()  : never
Exits the script with a specified HTTP status code and optional message.
redirect()  : void
Redirects the user to a specified URL
statusCode()  : mixed

Methods

exitWithErrorMessage()

Exit with an error message and set HTTP status code to 500 (Internal Server Error)

public exitWithErrorMessage([string $message = '' ]) : never
Parameters
$message : string = ''

The error message to display

Return values
never

exitWithMessage()

public exitWithMessage([string $message = '' ]) : never
Parameters
$message : string = ''
Return values
never

exitWithStatusCode()

Exits the script with a specified HTTP status code and optional message.

public exitWithStatusCode(int $code[, string|null $message = null ]) : never

This method sets the HTTP response status code and optionally outputs a message. The script execution stops after calling this method.

Parameters
$code : int

The HTTP status code to send (e.g., 404, 500).

$message : string|null = null

Optional message to display before exiting.

Return values
never

Returns control to the browser with the specified status code and message.

redirect()

Redirects the user to a specified URL

public redirect(string $url) : void
Parameters
$url : string

The URL to redirect to

statusCode()

public statusCode(int $code) : mixed
Parameters
$code : int
On this page

Search results