HttpStatusCode uses ConstantsTrait
Enumeration of standard HTTP status codes.
This class provides a centralized, type-safe list of common HTTP status codes, preserving the exact numeric values defined by the relevant RFCs (notably RFC 7231 and RFC 9110).
Usage examples:
- Access a status code: HttpStatusCode::OK
- Validate/inspect available codes with ConstantsTrait utilities:
- HttpStatusCode::enums() returns all status code values
- HttpStatusCode::includes(200) checks existence
- HttpStatusCode::getConstant(200) returns the constant name
Notes:
- Only widely used standardized status codes are listed.
Table of Contents
Constants
- ACCEPTED : int = 202
- ALREADY_REPORTED : int = 208
- BAD_GATEWAY : int = 502
- BAD_REQUEST : int = 400
- BANDWIDTH_LIMIT_EXCEEDED : int = 509
- BUSY : int = 600
- CONFLICT : int = 409
- CONTINUE : int = 100
- CREATED : int = 201
- DEFAULT : int = 0
- DISCONNECTED_OPERATION : int = 112
- EARLY_HINTS : int = 103
- EXPECTATION_FAILED : int = 417
- FAILED_DEPENDENCY : int = 424
- FORBIDDEN : int = 403
- FOUND : int = 302
- GATEWAY_TIMEOUT : int = 504
- GONE : int = 410
- HEURISTIC_EXPIRATION : int = 113
- HTTP_REQUEST_SENT_TO_HTTPS_PORT : int = 497
- HTTP_VERSION_NOT_SUPPORTED : int = 505
- IM_A_TEAPOT : int = 418
- IM_USED : int = 226
- INSUFFICIENT_STORAGE : int = 507
- INTERNAL_SERVER_ERROR : int = 500
- INVALID_TOKEN : int = 498
- LENGTH_REQUIRED : int = 411
- LOCKED : int = 423
- LOGIN_TIMEOUT : int = 440
- LOOP_DETECTED : int = 508
- METHOD_NOT_ALLOWED : int = 405
- MISCELLANEOUS_PERSISTENT_WARNING : int = 299
- MISCELLANEOUS_WARNING : int = 199
- MISDIRECTED_REQUEST : int = 421
- MOVED_PERMANENTLY : int = 301
- MULTI_STATUS : int = 207
- MULTIPLE_CHOICES : int = 300
- NETWORK_AUTHENTICATION_REQUIRED : int = 511
- NETWORK_CONNECTION_TIMEOUT_ERROR : int = 599
- NO_CONTENT : int = 204
- NON_AUTHORITATIVE_INFORMATION : int = 203
- NOT_ACCEPTABLE : int = 406
- NOT_EXTENDED : int = 510
- NOT_FOUND : int = 404
- NOT_IMPLEMENTED : int = 501
- NOT_MODIFIED : int = 304
- OK : int = 200
- PARTIAL_CONTENT : int = 206
- PAYLOAD_TOO_LARGE : int = 413
- PAYMENT_REQUIRED : int = 402
- PERMANENT_REDIRECT : int = 308
- PRECONDITION_FAILED : int = 412
- PRECONDITION_REQUIRED : int = 428
- PROCESSING : int = 102
- PROXY_AUTHENTICATION_REQUIRED : int = 407
- RANGE_NOT_SATISFIABLE : int = 416
- REQUEST_HEADER_FIELDS_TOO_LARGE : int = 431
- REQUEST_TIMEOUT : int = 408
- RESET_CONTENT : int = 205
- RESPONSE_IS_STALE : int = 110
- REVALIDATION_FAILED : int = 111
- SEE_OTHER : int = 303
- SERVICE_UNAVAILABLE : int = 503
- SWITCH_PROXY : int = 306
- SWITCHING_PROTOCOLS : int = 101
- TEMPORARY_REDIRECT : int = 307
- TOKEN_REQUIRED : int = 499
- TOO_EARLY : int = 425
- TOO_MANY_REQUESTS : int = 429
- TRANSFORMATION_APPLIED : int = 214
- UNAUTHORIZED : int = 401
- UNAVAILABLE_FOR_LEGAL_REASONS : int = 451
- UNPROCESSABLE_ENTITY : int = 422
- UNSUPPORTED_MEDIA_TYPE : int = 415
- UPGRADE_REQUIRED : int = 426
- URI_TOO_LONG : int = 414
- USE_PROXY : int = 305
- VARIANT_ALSO_NEGOTIATES : int = 506
Methods
- fromException() : int
- Returns the HTTP status code carried by `$e->getCode()` when it falls in the 4xx/5xx range — the convention used by oihana `Error4xx`/`Error5xx` exceptions which pass their status as the second argument of `Exception::__construct( $message , $code )`.
- getDescription() : string|null
- Returns the standard HTTP status description for a given code.
- getType() : string|null
- Returns the status type corresponding to a given HTTP status code.
Constants
ACCEPTED
public
int
ACCEPTED
= 202
ALREADY_REPORTED
public
int
ALREADY_REPORTED
= 208
BAD_GATEWAY
public
int
BAD_GATEWAY
= 502
BAD_REQUEST
public
int
BAD_REQUEST
= 400
BANDWIDTH_LIMIT_EXCEEDED
public
int
BANDWIDTH_LIMIT_EXCEEDED
= 509
BUSY
public
int
BUSY
= 600
CONFLICT
public
int
CONFLICT
= 409
CONTINUE
public
int
CONTINUE
= 100
CREATED
public
int
CREATED
= 201
DEFAULT
public
int
DEFAULT
= 0
DISCONNECTED_OPERATION
public
int
DISCONNECTED_OPERATION
= 112
EARLY_HINTS
public
int
EARLY_HINTS
= 103
EXPECTATION_FAILED
public
int
EXPECTATION_FAILED
= 417
FAILED_DEPENDENCY
public
int
FAILED_DEPENDENCY
= 424
FORBIDDEN
public
int
FORBIDDEN
= 403
FOUND
public
int
FOUND
= 302
GATEWAY_TIMEOUT
public
int
GATEWAY_TIMEOUT
= 504
GONE
public
int
GONE
= 410
HEURISTIC_EXPIRATION
public
int
HEURISTIC_EXPIRATION
= 113
HTTP_REQUEST_SENT_TO_HTTPS_PORT
public
int
HTTP_REQUEST_SENT_TO_HTTPS_PORT
= 497
HTTP_VERSION_NOT_SUPPORTED
public
int
HTTP_VERSION_NOT_SUPPORTED
= 505
IM_A_TEAPOT
public
int
IM_A_TEAPOT
= 418
IM_USED
public
int
IM_USED
= 226
INSUFFICIENT_STORAGE
public
int
INSUFFICIENT_STORAGE
= 507
INTERNAL_SERVER_ERROR
public
int
INTERNAL_SERVER_ERROR
= 500
INVALID_TOKEN
public
int
INVALID_TOKEN
= 498
LENGTH_REQUIRED
public
int
LENGTH_REQUIRED
= 411
LOCKED
public
int
LOCKED
= 423
LOGIN_TIMEOUT
public
int
LOGIN_TIMEOUT
= 440
LOOP_DETECTED
public
int
LOOP_DETECTED
= 508
METHOD_NOT_ALLOWED
public
int
METHOD_NOT_ALLOWED
= 405
MISCELLANEOUS_PERSISTENT_WARNING
public
int
MISCELLANEOUS_PERSISTENT_WARNING
= 299
MISCELLANEOUS_WARNING
public
int
MISCELLANEOUS_WARNING
= 199
MISDIRECTED_REQUEST
public
int
MISDIRECTED_REQUEST
= 421
MOVED_PERMANENTLY
public
int
MOVED_PERMANENTLY
= 301
MULTI_STATUS
public
int
MULTI_STATUS
= 207
MULTIPLE_CHOICES
public
int
MULTIPLE_CHOICES
= 300
NETWORK_AUTHENTICATION_REQUIRED
public
int
NETWORK_AUTHENTICATION_REQUIRED
= 511
NETWORK_CONNECTION_TIMEOUT_ERROR
public
int
NETWORK_CONNECTION_TIMEOUT_ERROR
= 599
NO_CONTENT
public
int
NO_CONTENT
= 204
NON_AUTHORITATIVE_INFORMATION
public
int
NON_AUTHORITATIVE_INFORMATION
= 203
NOT_ACCEPTABLE
public
int
NOT_ACCEPTABLE
= 406
NOT_EXTENDED
public
int
NOT_EXTENDED
= 510
NOT_FOUND
public
int
NOT_FOUND
= 404
NOT_IMPLEMENTED
public
int
NOT_IMPLEMENTED
= 501
NOT_MODIFIED
public
int
NOT_MODIFIED
= 304
OK
public
int
OK
= 200
PARTIAL_CONTENT
public
int
PARTIAL_CONTENT
= 206
PAYLOAD_TOO_LARGE
public
int
PAYLOAD_TOO_LARGE
= 413
PAYMENT_REQUIRED
public
int
PAYMENT_REQUIRED
= 402
PERMANENT_REDIRECT
public
int
PERMANENT_REDIRECT
= 308
PRECONDITION_FAILED
public
int
PRECONDITION_FAILED
= 412
PRECONDITION_REQUIRED
public
int
PRECONDITION_REQUIRED
= 428
PROCESSING
public
int
PROCESSING
= 102
PROXY_AUTHENTICATION_REQUIRED
public
int
PROXY_AUTHENTICATION_REQUIRED
= 407
RANGE_NOT_SATISFIABLE
public
int
RANGE_NOT_SATISFIABLE
= 416
REQUEST_HEADER_FIELDS_TOO_LARGE
public
int
REQUEST_HEADER_FIELDS_TOO_LARGE
= 431
REQUEST_TIMEOUT
public
int
REQUEST_TIMEOUT
= 408
RESET_CONTENT
public
int
RESET_CONTENT
= 205
RESPONSE_IS_STALE
public
int
RESPONSE_IS_STALE
= 110
REVALIDATION_FAILED
public
int
REVALIDATION_FAILED
= 111
SEE_OTHER
public
int
SEE_OTHER
= 303
SERVICE_UNAVAILABLE
public
int
SERVICE_UNAVAILABLE
= 503
SWITCH_PROXY
public
int
SWITCH_PROXY
= 306
SWITCHING_PROTOCOLS
public
int
SWITCHING_PROTOCOLS
= 101
TEMPORARY_REDIRECT
public
int
TEMPORARY_REDIRECT
= 307
TOKEN_REQUIRED
public
int
TOKEN_REQUIRED
= 499
TOO_EARLY
public
int
TOO_EARLY
= 425
TOO_MANY_REQUESTS
public
int
TOO_MANY_REQUESTS
= 429
TRANSFORMATION_APPLIED
public
int
TRANSFORMATION_APPLIED
= 214
UNAUTHORIZED
public
int
UNAUTHORIZED
= 401
UNAVAILABLE_FOR_LEGAL_REASONS
public
int
UNAVAILABLE_FOR_LEGAL_REASONS
= 451
UNPROCESSABLE_ENTITY
public
int
UNPROCESSABLE_ENTITY
= 422
UNSUPPORTED_MEDIA_TYPE
public
int
UNSUPPORTED_MEDIA_TYPE
= 415
UPGRADE_REQUIRED
public
int
UPGRADE_REQUIRED
= 426
URI_TOO_LONG
public
int
URI_TOO_LONG
= 414
USE_PROXY
public
int
USE_PROXY
= 305
VARIANT_ALSO_NEGOTIATES
public
int
VARIANT_ALSO_NEGOTIATES
= 506
Methods
fromException()
Returns the HTTP status code carried by `$e->getCode()` when it falls in the 4xx/5xx range — the convention used by oihana `Error4xx`/`Error5xx` exceptions which pass their status as the second argument of `Exception::__construct( $message , $code )`.
public
static fromException(Throwable $e) : int
Returns HttpStatusCode::INTERNAL_SERVER_ERROR otherwise, so unexpected runtime failures
(PHP Exception with default 0, driver-level exceptions with custom codes, etc.) still surface as 500.
Use it in catch( Throwable ) blocks of controllers to keep the
fail() response aligned with the actual error class, instead of
collapsing every 403/404/409/422/… to an opaque 500. Without this,
an Error403( 'Forbidden field: status' ) thrown by an inner
capability check arrives at the outer catch and the controller
loses the HTTP code before responding — masking the real
authorisation outcome from both the client and the audit log.
Parameters
- $e : Throwable
Tags
Return values
intgetDescription()
Returns the standard HTTP status description for a given code.
public
static getDescription(int|string $code) : string|null
The method normalizes the input to an integer and returns the
corresponding textual reason phrase (e.g., "OK", "Not Found",
"Internal Server Error"), based on the defined constants in this class.
The mapping includes:
- 1xx (100–199): Informational responses (e.g., "Continue", "Processing").
- 2xx (200–299): Successful responses (e.g., "OK", "Created").
- 3xx (300–399): Redirection messages (e.g., "Moved Permanently", "See Other").
- 4xx (400–499): Client error responses (e.g., "Bad Request", "Not Found").
- 5xx (500–599): Server error responses (e.g., "Internal Server Error", "Bad Gateway").
- Custom codes: Application-specific or extended values (e.g.,
"Busy").
If the given code does not match any predefined constant,
the method will return null.
Parameters
- $code : int|string
-
The HTTP status code to evaluate. Strings are cast to integers.
Return values
string|null —The human-readable status description associated with the code,
or null if no match is found.
getType()
Returns the status type corresponding to a given HTTP status code.
public
static getType(int|string $code) : string|null
The method normalizes the input to an integer and determines the category of the HTTP response based on its range:
- 1xx (100–199): info → Output::INFO
- 2xx (200–299): success → Output::SUCCESS
- 3xx (300–399): redirect → Output::REDIRECT
- 4xx (400–499): error | Client error → Output::ERROR
- 5xx (500–599): error | Server error → Output::ERROR
Any value outside these ranges will return null.
Parameters
- $code : int|string
-
The HTTP status code to evaluate. Strings are cast to integers.
Return values
string|null —One of the Output::* constants (INFO, SUCCESS, REDIRECT, ERROR)
if the code matches a known range, or null otherwise.