php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71618 http_response_code() can return bool
Submitted: 2016-02-17 19:05 UTC Modified: 2016-02-21 21:13 UTC
From: dschnepper at box dot com Assigned: tpunt (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.6.18 OS: Darwin (Macbook)
Private report: No CVE-ID: None
 [2016-02-17 19:05 UTC] dschnepper at box dot com
Description:
------------
---
From manual page: http://www.php.net/function.http-response-code
---

$ uname -a
Darwin mbp-001898.local 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep  1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64

$ php --version
PHP 5.6.18 (cli) (built: Feb  6 2016 06:47:15) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with XCache v3.2.0, Copyright (c) 2005-2014, by mOo
    with augmented_types v0.6.6, Copyright (c) 2013, by jmarrama@box.com, abishopric@box.com
    with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans
    with XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo

$ cat http.php
<?php

var_dump(http_response_code());
var_dump(http_response_code(200));
var_dump(http_response_code(302));
var_dump(http_response_code());
var_dump(http_response_code(false));
var_dump(http_response_code());
var_dump(http_response_code(12345678901234567890));
var_dump(http_response_code());
var_dump(http_response_code(-1));
var_dump(http_response_code());

$ php http.php
bool(false)
bool(true)
int(200)
int(302)
int(302)
int(302)
int(302)
int(-350287872)
int(-350287872)
int(-1)

----
false is returned when there is no current http_response_code setting.
true is returned when there is no current http_response_code setting, but the current call set one.

true & false are accepted as input parameters - but ignored.

Out of range for valid HTTP values are accepted (-1, large numbers, etc).


Test script:
---------------
<?php

var_dump(http_response_code());
var_dump(http_response_code(200));
var_dump(http_response_code(302));
var_dump(http_response_code());
var_dump(http_response_code(false));
var_dump(http_response_code());
var_dump(http_response_code(12345678901234567890));
var_dump(http_response_code());
var_dump(http_response_code(-1));
var_dump(http_response_code());


Expected result:
----------------
int(200)
int(200)                                
int(200)
int(302)
int(302)
int(302)
int(302)
int(-350287872)
int(-350287872)
int(-1)


Actual result:
--------------
bool(false)
bool(true)
int(200)
int(302)
int(302)
int(302)
int(302)
int(-350287872)
int(-350287872)
int(-1)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-17 19:07 UTC] dschnepper at box dot com
The significant fix to the documentation is to note that http_response_code *can* return a bool.  Or perhaps this is an implementation error, as the documentation clearly states 200 is the default result.
 [2016-02-17 19:24 UTC] requinix@php.net
The current implementation in ext/standard/head.c returns:
- True if a new $response_code was given and one wasn't already set by the SAPI - "the new code was set"
- False if a new $response_code was not given and one wasn't already set by the SAPI - "there was no code set"
- int as expected, otherwise

So this could be a bug bug (code shouldn't be returning true/false and should be returning 200 as a default) or doc bug (code can return true/false).
 [2016-02-21 21:10 UTC] tpunt@php.net
Automatic comment from SVN on behalf of tpunt
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=338620
Log: Resolve doc bug #71618
 [2016-02-21 21:13 UTC] tpunt@php.net
Given that the source code for this function [1] intentionally returns boolean values, I've taken this to be a documentation problem. The documentation has now been updated to reflect boolean return values.

[1]: http://lxr.php.net/xref/PHP_7_0/ext/standard/head.c#293
 [2016-02-21 21:13 UTC] tpunt@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: tpunt
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 10:00:01 2026 UTC