Menu
Reference
Status
finalclass
final class Status
HTTP status codes as integer constants, plus helpers for the response path.
A class of const int rather than an enum, so the value is a plain int everywhere it is
compared or sent. Pass a constant wherever a status is expected: new
Response(Status::NOT_FOUND).
Example
// Http\Status constants and helpers, Http\Method cases and predicates.
use Http\{Method, Status};
echo Status::NOT_FOUND, ' ', Status::text(Status::NOT_FOUND), "\n";
echo Status::text(299) === '' ? "299 has no phrase\n" : "unexpected\n";
foreach ([200, 204, 301, 304, 404] as $code) {
echo $code, ': redirect=', var_export(Status::isRedirect($code), true),
' body=', var_export(Status::hasBody($code), true), "\n";
}
foreach (Method::cases() as $m) {
echo str_pad($m->value, 8),
'safe=', var_export($m->isSafe(), true),
' idempotent=', var_export($m->isIdempotent(), true),
' body=', var_export($m->allowsBody(), true), "\n";
}
var_dump(Method::tryFrom('PROPFIND'));Output
404 Not Found
299 has no phrase
200: redirect=false body=true
204: redirect=false body=false
301: redirect=true body=true
304: redirect=false body=false
404: redirect=false body=true
GET safe=true idempotent=true body=false
HEAD safe=true idempotent=true body=false
POST safe=false idempotent=false body=true
PUT safe=false idempotent=true body=true
PATCH safe=false idempotent=false body=true
DELETE safe=false idempotent=true body=false
OPTIONS safe=true idempotent=true body=false
TRACE safe=true idempotent=true body=false
CONNECT safe=false idempotent=false body=false
NULLSee also: Response
Constants
CONTINUE | 100 | 100 Continue. |
SWITCHING_PROTOCOLS | 101 | 101 Switching Protocols. |
OK | 200 | 200 OK. |
CREATED | 201 | 201 Created. |
ACCEPTED | 202 | 202 Accepted. |
NO_CONTENT | 204 | 204 No Content. |
PARTIAL_CONTENT | 206 | 206 Partial Content. |
MOVED_PERMANENTLY | 301 | 301 Moved Permanently. |
FOUND | 302 | 302 Found. |
SEE_OTHER | 303 | 303 See Other. |
NOT_MODIFIED | 304 | 304 Not Modified. |
TEMPORARY_REDIRECT | 307 | 307 Temporary Redirect. |
PERMANENT_REDIRECT | 308 | 308 Permanent Redirect. |
BAD_REQUEST | 400 | 400 Bad Request. |
UNAUTHORIZED | 401 | 401 Unauthorized. |
FORBIDDEN | 403 | 403 Forbidden. |
NOT_FOUND | 404 | 404 Not Found. |
METHOD_NOT_ALLOWED | 405 | 405 Method Not Allowed. |
NOT_ACCEPTABLE | 406 | 406 Not Acceptable. |
REQUEST_TIMEOUT | 408 | 408 Request Timeout. |
CONFLICT | 409 | 409 Conflict. |
GONE | 410 | 410 Gone. |
LENGTH_REQUIRED | 411 | 411 Length Required. |
PRECONDITION_FAILED | 412 | 412 Precondition Failed. |
CONTENT_TOO_LARGE | 413 | 413 Content Too Large. |
URI_TOO_LONG | 414 | 414 URI Too Long. |
UNSUPPORTED_MEDIA_TYPE | 415 | 415 Unsupported Media Type. |
RANGE_NOT_SATISFIABLE | 416 | 416 Range Not Satisfiable. |
EXPECTATION_FAILED | 417 | 417 Expectation Failed. |
MISDIRECTED_REQUEST | 421 | 421 Misdirected Request. |
UNPROCESSABLE_CONTENT | 422 | 422 Unprocessable Content. |
TOO_EARLY | 425 | 425 Too Early. |
UPGRADE_REQUIRED | 426 | 426 Upgrade Required. |
PRECONDITION_REQUIRED | 428 | 428 Precondition Required. |
TOO_MANY_REQUESTS | 429 | 429 Too Many Requests. |
REQUEST_HEADER_FIELDS_TOO_LARGE | 431 | 431 Request Header Fields Too Large. |
INTERNAL_SERVER_ERROR | 500 | 500 Internal Server Error. |
NOT_IMPLEMENTED | 501 | 501 Not Implemented. |
BAD_GATEWAY | 502 | 502 Bad Gateway. |
SERVICE_UNAVAILABLE | 503 | 503 Service Unavailable. |
GATEWAY_TIMEOUT | 504 | 504 Gateway Timeout. |
HTTP_VERSION_NOT_SUPPORTED | 505 | 505 HTTP Version Not Supported. |
Methods
text() | The reason phrase for a status code, or '' for a code without one. |
isRedirect() | Whether a code is one of the redirects redirect() is meant for. |
hasBody() | Whether a response with this code may carry a body at all (§6.4.1). |
text()#source
static function text(int $code): string
The reason phrase for a status code, or '' for a code without one.
Parameters
$codeint- HTTP status code.
Returns
string — The phrase, for example Not Found.
isRedirect()#source
static function isRedirect(int $code): bool
Whether a code is one of the redirects redirect() is meant for.
Parameters
$codeint- HTTP status code.
Returns
bool — true for 301, 302, 303, 307 and 308.
hasBody()#source
static function hasBody(int $code): bool
Whether a response with this code may carry a body at all (§6.4.1). 1xx, 204 and 304 may not — not even a Content-Length: 0.
Parameters
$codeint- HTTP status code.
Returns
bool — false for 1xx, 204 and 304; true otherwise.