Menu

Reference / Http

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
NULL

See also: Response

Constants

CONTINUE100100 Continue.
SWITCHING_PROTOCOLS101101 Switching Protocols.
OK200200 OK.
CREATED201201 Created.
ACCEPTED202202 Accepted.
NO_CONTENT204204 No Content.
PARTIAL_CONTENT206206 Partial Content.
MOVED_PERMANENTLY301301 Moved Permanently.
FOUND302302 Found.
SEE_OTHER303303 See Other.
NOT_MODIFIED304304 Not Modified.
TEMPORARY_REDIRECT307307 Temporary Redirect.
PERMANENT_REDIRECT308308 Permanent Redirect.
BAD_REQUEST400400 Bad Request.
UNAUTHORIZED401401 Unauthorized.
FORBIDDEN403403 Forbidden.
NOT_FOUND404404 Not Found.
METHOD_NOT_ALLOWED405405 Method Not Allowed.
NOT_ACCEPTABLE406406 Not Acceptable.
REQUEST_TIMEOUT408408 Request Timeout.
CONFLICT409409 Conflict.
GONE410410 Gone.
LENGTH_REQUIRED411411 Length Required.
PRECONDITION_FAILED412412 Precondition Failed.
CONTENT_TOO_LARGE413413 Content Too Large.
URI_TOO_LONG414414 URI Too Long.
UNSUPPORTED_MEDIA_TYPE415415 Unsupported Media Type.
RANGE_NOT_SATISFIABLE416416 Range Not Satisfiable.
EXPECTATION_FAILED417417 Expectation Failed.
MISDIRECTED_REQUEST421421 Misdirected Request.
UNPROCESSABLE_CONTENT422422 Unprocessable Content.
TOO_EARLY425425 Too Early.
UPGRADE_REQUIRED426426 Upgrade Required.
PRECONDITION_REQUIRED428428 Precondition Required.
TOO_MANY_REQUESTS429429 Too Many Requests.
REQUEST_HEADER_FIELDS_TOO_LARGE431431 Request Header Fields Too Large.
INTERNAL_SERVER_ERROR500500 Internal Server Error.
NOT_IMPLEMENTED501501 Not Implemented.
BAD_GATEWAY502502 Bad Gateway.
SERVICE_UNAVAILABLE503503 Service Unavailable.
GATEWAY_TIMEOUT504504 Gateway Timeout.
HTTP_VERSION_NOT_SUPPORTED505505 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

$code int
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

$code int
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

$code int
HTTP status code.

Returns

bool — false for 1xx, 204 and 304; true otherwise.

View source