Arrays as static properties in php

The syntax is a little strange (note the self::$..) below:


// the space at the start of each value is required
private static $httpResponseCodes = array('200' => ' 200 OK'
, '400' => ' 400 Bad Request'
, '401' => ' 401 Unauthorized'
, '403' => ' 403 Forbidden'
, '404' => ' 404 Not Found'
, '408' => ' 408 Request Timeout'
, '409' => ' 409 Conflict'
, '500' => ' 500 Internal Server Error'
, '503' => ' 503 Service Unavailable'
);

public static function lookupHTTPResponse($code) {
// if passed a code which does not exist then return 500
if (! isset(self::$httpResponseCodes[$code])) {
$code = '500';
}
return self::$httpResponseCodes[$code];
}

Comments

Popular posts from this blog

deep dive into Material UI TextField built by mui

angular js protractor e2e cheatsheet

react-router v6.4+ loaders, actions, forms and more