PHP Luminova: HTTP Status Codes
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
LABELSconstant - Retrieve a label by code using
get() - Fetch a label directly using magic methods such as
status200() isValid()protects inputs before headers are sentisError()avoids magic number checks (>= 400)phrase()gives predictable output without exceptions
Examples
Get status code
echo HttpStatus::OK; // 200Retrieve all status codes and messages:
HttpStatus::get();
// or
HttpStatus::LABELS;Get the message for HTTP 200:
echo HttpStatus::status200(); // OKGet the message for HTTP 503:
echo HttpStatus::status503(); // Service UnavailableGet a message using the numeric code:
echo HttpStatus::phrase(400); // Bad RequestClass 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)
| Constant | Code | Description |
|---|---|---|
CONTINUE | 100 | Request received, continue processing |
SWITCHING_PROTOCOLS | 101 | Protocol switch acknowledged |
PROCESSING | 102 | Request is being processed |
EARLY_HINTS | 103 | Request early hints |
Success (2xx)
| Constant | Code | Description |
|---|---|---|
OK | 200 | Request successful |
CREATED | 201 | Resource created |
ACCEPTED | 202 | Request accepted for processing |
NON_AUTHORITATIVE_INFORMATION | 203 | Response from a third-party source |
NO_CONTENT | 204 | Successful request with no body |
RESET_CONTENT | 205 | Client should reset the view |
PARTIAL_CONTENT | 206 | Partial response |
MULTI_STATUS | 207 | Multiple status responses |
ALREADY_REPORTED | 208 | Request already reported |
IM_USED | 226 | Port already in-use |
Redirection (3xx)
| Constant | Code | Description |
|---|---|---|
MULTIPLE_CHOICES | 300 | Multiple response options |
MOVED_PERMANENTLY | 301 | Resource moved permanently |
MOVED_TEMPORARILY | 302 | Resource moved temporarily |
SEE_OTHER | 303 | Retrieve resource from another URI |
NOT_MODIFIED | 304 | Cached version is still valid |
USE_PROXY | 305 | Must access resource via proxy |
SWITCH_PROXY | 306 | Reserved, no longer used |
TEMPORARY_REDIRECT | 307 | Temporary redirect |
PERMANENTLY_REDIRECT | 308 | Permanent redirect |
Client Errors (4xx)
| Constant | Code | Description |
|---|---|---|
BAD_REQUEST | 400 | Malformed request |
UNAUTHORIZED | 401 | Authentication required |
PAYMENT_REQUIRED | 402 | Reserved for future use |
FORBIDDEN | 403 | Access denied |
NOT_FOUND | 404 | Resource not found |
METHOD_NOT_ALLOWED | 405 | HTTP method not allowed |
NOT_ACCEPTABLE | 406 | Cannot satisfy request headers |
PROXY_AUTHENTICATION_REQUIRED | 407 | Proxy authentication required |
REQUEST_TIMEOUT | 408 | Request timed out |
CONFLICT | 409 | Request conflict |
GONE | 410 | Resource permanently removed |
LENGTH_REQUIRED | 411 | Content-Length required |
PRECONDITION_FAILED | 412 | Preconditions failed |
REQUEST_ENTITY_TOO_LARGE | 413 | Payload too large |
REQUEST_URI_TOO_LONG | 414 | URI too long |
UNSUPPORTED_MEDIA_TYPE | 415 | Unsupported media type |
REQUESTED_RANGE_NOT_SATISFIABLE | 416 | Invalid range |
EXPECTATION_FAILED | 417 | Expectation failed |
I_AM_A_TEAPOT | 418 | RFC 2324 joke status |
AUTHENTICATION_TIMEOUT | 419 | Authentication timeout |
ENHANCE_YOUR_CALM | 420 | Rate limiting (non-standard) |
MISDIRECTED_REQUEST | 421 | Misdirected Request |
UNPROCESSABLE_ENTITY | 422 | Semantic error |
LOCKED | 423 | Resource locked |
FAILED_DEPENDENCY | 424 | Dependency failure |
METHOD_FAILURE | 424 | Legacy alias |
TOO_EARLY | 425 | Request too early |
UPGRADE_REQUIRED | 426 | Protocol upgrade required |
PRECONDITION_REQUIRED | 428 | Preconditions required |
TOO_MANY_REQUESTS | 429 | Rate limit exceeded |
REQUEST_HEADER_FIELDS_TOO_LARGE | 431 | Headers too large |
NO_RESPONSE | 444 | No response returned |
RETRY_WITH | 449 | Retry request |
BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS | 450 | Access blocked |
UNAVAILABLE_FOR_LEGAL_REASONS | 451 | Legal restriction |
REQUEST_HEADER_TOO_LARGE | 494 | Header too large |
CERT_ERROR | 495 | SSL certificate error |
NO_CERT | 496 | Client certificate missing |
HTTP_TO_HTTPS | 497 | HTTP request sent to HTTPS |
CLIENT_CLOSED_REQUEST | 499 | Client closed connection |
Server Errors (5xx)
| Constant | Code | Description |
|---|---|---|
INTERNAL_SERVER_ERROR | 500 | Generic server error |
NOT_IMPLEMENTED | 501 | Feature not implemented |
BAD_GATEWAY | 502 | Invalid upstream response |
SERVICE_UNAVAILABLE | 503 | Service unavailable |
GATEWAY_TIMEOUT | 504 | Gateway timeout |
HTTP_VERSION_NOT_SUPPORTED | 505 | HTTP version unsupported |
VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL | 506 | Variant negotiation error |
INSUFFICIENT_STORAGE | 507 | Insufficient storage |
LOOP_DETECTED | 508 | Infinite loop detected |
BANDWIDTH_LIMIT_EXCEEDED | 509 | Bandwidth limit exceeded |
NOT_EXTENDED | 510 | Further extensions required |
NETWORK_AUTHENTICATION_REQUIRED | 511 | Network authentication required |
NETWORK_READ_TIMEOUT_ERROR | 598 | Network read timeout |
NETWORK_CONNECT_TIMEOUT_ERROR | 599 | Network connection timeout |
Notes:
- Constants represent meaning, not presentation
- Labels are resolved via
LABELSor 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(mixed $code): boolParameters
| Name | Type | Description |
|---|---|---|
$code | int | HTTP status code to validate. |
Return:
bool - Return true — if the code is between 100 and 599, false — otherwise
Example
HttpStatus::isValid(200); // true
HttpStatus::isValid(99); // falseisError
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): boolParameters
| Name | Type | Description |
|---|---|---|
$code | mixed | HTTP status code to check. |
Return:
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); // falsephrase
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'): stringParameters
| Name | Type | Description |
|---|---|---|
$code | int | HTTP status code (e.g. 200, 404). |
$fallback | string|null | Value to return when the code is not found. |
Return:
string - Return status message or fallback value
Examples
HttpStatus::phrase(200);
// OK
HttpStatus::phrase(999);
// Invalid
HttpStatus::phrase(999, null);
// ''get
Get the full map of status codes and reason phrases.
public static function get(): arrayReturn:
array<int,string> - Returns the HTTP reason phrases keyed by status code. Use phrase() to look up one code.
statusXXX (magic method)
Returns a status message using a magic static call.
Method name format:
status + HTTP codeExample:
HttpStatus::status404();Return:
string|null - Returns the status phrase, or null for an undefined code.
isInformational
Check for an informational status.
public static function isInformational(int $code): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$code | int | HTTP status code. |
Return:
bool - Returns true for codes 100 through 199.
isSuccess
Check for a successful status.
public static function isSuccess(int $code): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$code | int | HTTP status code. |
Return:
bool - Returns true for codes 200 through 299.
isAccepted
Check whether a request was accepted for processing.
public static function isAccepted(int $code): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$code | int | HTTP status code. |
Return:
bool - Returns true for code 202.
isNoContent
Check whether the status indicates a response without content.
public static function isNoContent(int $code): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$code | int | HTTP status code. |
Return:
bool - Returns true for 204, 205, or 304.
isRedirect
Check for a redirection status.
public static function isRedirect(int $code): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$code | int | HTTP status code. |
Return:
bool - Returns true for codes 300 through 399.
isClientError
Check for a client error.
public static function isClientError(int $code): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$code | int | HTTP status code. |
Return:
bool - Returns true for codes 400 through 499.
isServerError
Check for a server error.
public static function isServerError(int $code): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$code | int | HTTP status code. |
Return:
bool - Returns true for codes 500 through 599.