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::get(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 |
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 |
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 |
UNUSED | 306 | Reserved, no longer used |
TEMPORARY_REDIRECT | 307 | Temporary redirect |
PERMANENT_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_LARGE | 414 | URI too long |
UNSUPPORTED_MEDIA_TYPE | 415 | Unsupported media type |
REQUESTED_RANGE_NOT_SATISFIABLE | 416 | Invalid range |
EXPECTATION_FAILED | 417 | Expectation failed |
IM_A_TEAPOT | 418 | RFC 2324 joke status |
AUTHENTICATION_TIMEOUT | 419 | Authentication timeout |
ENHANCE_YOUR_CALM | 420 | Rate limiting (non-standard) |
UNPROCESSABLE_ENTITY | 422 | Semantic error |
LOCKED | 423 | Resource locked |
FAILED_DEPENDENCY | 424 | Dependency failure |
METHOD_FAILURE | 424 | Legacy alias |
UNORDERED_COLLECTION | 425 | Collection not ordered |
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 | 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(int $code): boolParameters
| Name | Type | Description |
|---|---|---|
$code | int | HTTP 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); // 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 | int | HTTP 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); // 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 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|nullParameters
| Name | Type | Description |
|---|---|---|
$code | int|null | HTTP status code (e.g. 200, 404). If null, all statuses are returned. |
Return Value:
string— status message if the code existsarray<int,string>— all status codes and messages if$codeisnullnull— if the code is not defined
statusXXX (magic method)
Returns a status message using a magic static call.
Method name format:
status + HTTP codeExample:
HttpStatus::status404();Signature
public static function statusXXX(): ?stringReturn Value:
string— status messagenull— if the status code is not defined