为什么Zend_Http_Response将状态码除以100 ?


Why does Zend_Http_Response divide status codes by 100

我在Zend看到一些代码后的开发人员模式,我试图弄清楚为什么Zend可能已经实现了http响应代码检查这种方式:

/**
 * Check whether the response in successful
 *
 * @return boolean
 */
public function isSuccessful()
{
    $restype = floor($this->code / 100);
    if ($restype == 2 || $restype == 1) { // Shouldn't 3xx count as success as well ???
        return true;
    }
    return false;
}

具体来说,为什么他们要这样做而不是

public function isSuccessful()
{
    return $this->code >= 100 && $this->code < 300
}

可能是因为他们只关心

5 3

4 4

4 1

3 02

2 01

等等,我们主要关心的是errortype类而不是具体的

看这段代码,除了开发者的个人选择,我不认为有任何其他原因。