PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTTP » HTTP_Request » Bug #842

wrong return type and values

Details

Submitted2004-02-23 15:27 UTC
Frommaka3d at yahoo dot com dot br
Assignedavb
StatusClosed
PackageHTTP_Request
PHP Version4.3.4
OSirrelevant
Roadmaps(Not assigned)

Comments

[2004-02-23 15:27 UTC] maka3d at yahoo dot com dot br

Description:
------------
gerResponseCookies should return array()
getResponseCode should return 0
getResponseCode should return '' // empty string

gerResponseCookies and getResponseHeaders should return empty array.

at line 634 change for this

return isset($this->_response->_headers) ? $this->_response->_headers : array();

[2004-02-23 21:01 UTC] maka3d at yahoo dot com dot br

Hi there, thanks for fast reply! :)

I'll coment one by one now:

1) getResponseCode

at line 617 out document that it return int, what's wrong since it
return false. You have to paths to follow:
1 - change the "return int" to return mixed.
2 - Change the return false to return 0

I suggest 2 since at line 567 and 568 you do a math comparation:
AND $this->getResponseCode() > 300
AND $this->getResponseCode() < 399

2) getResponseBody

the above apply for this too.

3) getResponseHeader and getResponseCookies are more dangerous.

at line 629 is documented:

* @return mixed either the value of $headername or an array of all header values

as you see, it doesn't says : and false if no response given.

I think return an empty array is better cause you can apply any array_function to the

return of this method without the need to check if it's an array or not.
as example you change this:

if( is_array($request->getResponseHeader()) ){
foreach($request->getResponseHeader() as $key=>$value){
// do something
}
}

for this since you know it gives always an array as return:

foreach($request->getResponseHeader() as $key=>$value){
// do something
}

you can to know more about this looking at pear devel list
for a post titled "What return type use?"

[2004-02-27 21:57 UTC] maka3d at yahoo dot com dot br

again, thanks for the fast reply! :)