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

Issue Type: Bug Created: 2011-09-29T07:48:44.000+0000 Last Updated: 2011-11-11T19:24:23.000+0000 Status: Resolved Fix version(s): Reporter: John Smith (darksmith) Assignee: Ralph Schindler (ralph) Tags: - Zend\Http

Related issues: Attachments:


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


Posted by Radosław Benkel (singles) on 2011-11-11T19:22:05.000+0000

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

<pre class="highlight">
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;

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.