ZF2-73: Invalid return type on Zend\Http\Response->getStatusCode()


When the statusCode is assigned in the static method {{fromString}} it's not converted into an int. Then in the {{setStatusCode}} method the {{is_numeric}} check is ok because the constant exist (the status code is a string at this point and {{$const = get_called_class() . '::STATUS_CODE_' . $code;}} exists if the http status code is valid). Finally the {{statusCode}} property is assigned but as a string.

How to test this issue :

{{$response}} is a response with a spec-valid http status code.

{{$response->getStatusCode() === 200}}


At the end of setStatusCode(), code is casted to integer.

public function setStatusCode($code)
    $const = get_called_class() . '::STATUS_CODE_' . $code;
    if (!is_numeric($code) || !defined($const)) {
        $code = is_scalar($code) ? $code : gettype($code);
        throw new Exception\InvalidArgumentException(sprintf(
            'Invalid status code provided: "%s"',
    $this->statusCode = (int) $code;
    return $this;