Skip to content

HttpStatus

The single source of truth for HTTP status-code validity and reason phrases.

Validity is a range check, not membership of a code list: the IANA registry grows, and a framework that has to be edited before an application can emit a new status code blocks that application for no benefit. Status validity is also independent of the protocol version carrying it.

final class HttpStatus

Since3.2.0
SourceHttp/HttpStatus.php
ConstantValueDescription
MAX599Highest status code the three-digit wire format permits.
MIN100Lowest status code any HTTP version permits.
MethodDescription
[`isRedirect(stringint $code): bool`](#isredirect)
[`isValid(stringint $code): bool`](#isvalid)
[`phrase(stringint $code): string`](#phrase)

public static function isRedirect(string|int $code): bool

Whether $code is a redirect status that carries a Location header.

304 is deliberately excluded: it is a 3xx but not a redirect.

ParameterTypeDescription
$code`string““int`

Returns bool

public static function isValid(string|int $code): bool

Whether $code can be sent as an HTTP status.

Accepts a numeric string as well as an int, because the response API carries string|int status codes and config-sourced codes arrive as strings. A non-numeric string, or anything outside 100-599, is rejected.

ParameterTypeDescription
$code`string““int`

Returns bool

public static function phrase(string|int $code): string

The reason phrase for $code, or a generic class-derived phrase for a valid code with no registered phrase.

An invalid code yields the empty string, which PSR-7 permits as a reason phrase, keeping this total rather than throwing.

ParameterTypeDescription
$code`string““int`

Returns string