Luminova Framework

PHP Luminova: HTTP Status Codes

Last updated: 2026-01-16 09:15:26

Helper class for working with HTTP status codes and their reason phrases.

The HttpStatus class provides HTTP status codes and their reason phrases.It is a static utility class and cannot be instantiated.

You can:

  • Access all status labels via the LABELS constant
  • Retrieve a label by code using get()
  • Fetch a label directly using magic methods such as status200()
  • isValid() protects inputs before headers are sent
  • isError() avoids magic number checks (>= 400)
  • phrase() gives predictable output without exceptions

Examples

Get status code

echo HttpStatus::OK // 200

Retrieve all status codes and messages:

HttpStatus::get();
// or
HttpStatus::LABELS;

Get the message for HTTP 200:

echo HttpStatus::status200(); // OK

Get the message for HTTP 503:

echo HttpStatus::status503(); // Service Unavailable

Get a message using the numeric code:

echo HttpStatus::get(400); // Bad Request

Class Definition

  • Class namespace: Luminova\Http\HttpStatus
  • This class is marked as final and can't be subclassed
  • Instantiation: Not allowed (static access only)

Constants

HTTP Status Constants

All constants represent valid HTTP status codes and are grouped by category.Each constant maps directly to its numeric status code.


Informational (1xx)

ConstantCodeDescription
CONTINUE100Request received, continue processing
SWITCHING_PROTOCOLS101Protocol switch acknowledged
PROCESSING102Request is being processed

Success (2xx)

ConstantCodeDescription
OK200Request successful
CREATED201Resource created
ACCEPTED202Request accepted for processing
NON_AUTHORITATIVE_INFORMATION203Response from a third-party source
NO_CONTENT204Successful request with no body
RESET_CONTENT205Client should reset the view
PARTIAL_CONTENT206Partial response
MULTI_STATUS207Multiple status responses

Redirection (3xx)

ConstantCodeDescription
MULTIPLE_CHOICES300Multiple response options
MOVED_PERMANENTLY301Resource moved permanently
MOVED_TEMPORARILY302Resource moved temporarily
SEE_OTHER303Retrieve resource from another URI
NOT_MODIFIED304Cached version is still valid
USE_PROXY305Must access resource via proxy
UNUSED306Reserved, no longer used
TEMPORARY_REDIRECT307Temporary redirect
PERMANENT_REDIRECT308Permanent redirect

Client Errors (4xx)

ConstantCodeDescription
BAD_REQUEST400Malformed request
UNAUTHORIZED401Authentication required
PAYMENT_REQUIRED402Reserved for future use
FORBIDDEN403Access denied
NOT_FOUND404Resource not found
METHOD_NOT_ALLOWED405HTTP method not allowed
NOT_ACCEPTABLE406Cannot satisfy request headers
PROXY_AUTHENTICATION_REQUIRED407Proxy authentication required
REQUEST_TIMEOUT408Request timed out
CONFLICT409Request conflict
GONE410Resource permanently removed
LENGTH_REQUIRED411Content-Length required
PRECONDITION_FAILED412Preconditions failed
REQUEST_ENTITY_TOO_LARGE413Payload too large
REQUEST_URI_TOO_LARGE414URI too long
UNSUPPORTED_MEDIA_TYPE415Unsupported media type
REQUESTED_RANGE_NOT_SATISFIABLE416Invalid range
EXPECTATION_FAILED417Expectation failed
IM_A_TEAPOT418RFC 2324 joke status
AUTHENTICATION_TIMEOUT419Authentication timeout
ENHANCE_YOUR_CALM420Rate limiting (non-standard)
UNPROCESSABLE_ENTITY422Semantic error
LOCKED423Resource locked
FAILED_DEPENDENCY424Dependency failure
METHOD_FAILURE424Legacy alias
UNORDERED_COLLECTION425Collection not ordered
UPGRADE_REQUIRED426Protocol upgrade required
PRECONDITION_REQUIRED428Preconditions required
TOO_MANY_REQUESTS429Rate limit exceeded
REQUEST_HEADER_FIELDS_TOO_LARGE431Headers too large
NO_RESPONSE444No response returned
RETRY_WITH449Retry request
BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS450Access blocked
UNAVAILABLE_FOR_LEGAL_REASONS451Legal restriction
REQUEST_HEADER_TOO_LARGE494Header too large
CERT_ERROR495SSL certificate error
NO_CERT496Client certificate missing
HTTP_TO_HTTPS497HTTP request sent to HTTPS
CLIENT_CLOSED_REQUEST499Client closed connection

Server Errors (5xx)

ConstantCodeDescription
INTERNAL_SERVER_ERROR500Generic server error
NOT_IMPLEMENTED501Feature not implemented
BAD_GATEWAY502Invalid upstream response
SERVICE_UNAVAILABLE503Service unavailable
GATEWAY_TIMEOUT504Gateway timeout
HTTP_VERSION_NOT_SUPPORTED505HTTP version unsupported
VARIANT_ALSO_NEGOTIATES506Variant negotiation error
INSUFFICIENT_STORAGE507Insufficient storage
LOOP_DETECTED508Infinite loop detected
BANDWIDTH_LIMIT_EXCEEDED509Bandwidth limit exceeded
NOT_EXTENDED510Further extensions required
NETWORK_AUTHENTICATION_REQUIRED511Network authentication required
NETWORK_READ_TIMEOUT_ERROR598Network read timeout
NETWORK_CONNECT_TIMEOUT_ERROR599Network connection timeout

Notes:

  • Constants represent meaning, not presentation
  • Labels are resolved via LABELS or helper methods
  • Non-standard codes are included for real-world compatibility

LABELS

Contains all supported HTTP status codes mapped to their reason phrases.

public const LABELS = [
    200 => 'OK',
    // ...
];

Methods

isValid

Checks whether a value is within the valid HTTP status code range.

public static function isValid(int $code): bool

Parameters

NameTypeDescription
$codeintHTTP status code to validate.

Return Value:

bool Return true — if the code is between 100 and 599, false — otherwise

Example

HttpStatus::isValid(200); // true
HttpStatus::isValid(99);  // false

isError

Determines whether a status code represents an error.

A code is considered an error if it falls within:

  • 4xx (client errors)
  • 5xx (server errors)
public static function isError(int $code): bool

Parameters

NameTypeDescription
$codeintHTTP status code to check.

Return Value:

bool — Return true if the code is between 400 and 599, false otherwise

Example

HttpStatus::isError(404); // true
HttpStatus::isError(503); // true
HttpStatus::isError(200); // false

phrase

Returns the HTTP status message for a given code.

If the code is not defined, the fallback value is returned.If the fallback is null, an empty string is returned.

public static function phrase(int $code, ?string $fallback = 'Invalid'): string

Parameters

NameTypeDescription
$codeintHTTP status code (e.g. 200, 404).
$fallbackstring|nullValue to return when the code is not found.

Return Value:

string — Return status message or fallback value

Examples

HttpStatus::phrase(200); 
// OK

HttpStatus::phrase(999); 
// Invalid

HttpStatus::phrase(999, null); 
// ''

get

Returns a status message for a given HTTP code, or all status messages when no code is provided.

public static function get(?int $code = null): array|string|null

Parameters

NameTypeDescription
$codeint|nullHTTP status code (e.g. 200, 404). If null, all statuses are returned.

Return Value:

  • string — status message if the code exists
  • array<int,string> — all status codes and messages if $code is null
  • null — if the code is not defined

statusXXX (magic method)

Returns a status message using a magic static call.

Method name format:

status + HTTP code

Example:

HttpStatus::status404();

Signature

public static function statusXXX(): ?string

Return Value:

  • string — status message
  • null — if the status code is not defined