Doc #71618 [Com]: http_response_code() can return bool
| From: | tpunt@php.net | Date: | Sun, 21 Feb 2016 21:13:39 +0000 |
| Subject: | Doc #71618 [Com]: http_response_code() can return bool | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13204@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71618&edit=1
ID: 71618
Comment by: tpunt@php.net
Reported by: dschnepper at box dot com
Summary: http_response_code() can return bool
Status: Open
Type: Documentation Problem
Package: Documentation problem
Operating System: Darwin (Macbook)
PHP Version: 5.6.18
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2016-02-21 21:10:15] tpunt@php.net
Automatic comment from SVN on behalf of tpunt
Revision: http://svn.php.net/viewvc/?view=revision&revision=338620
Log: Resolve doc bug #71618
------------------------------------------------------------------------
[2016-02-17 19:24:15] 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-17 19:07:45] 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:05:53] 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)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71618&edit=1