Skip to content

Commit ed37de7

Browse files
committed
Fix php-curl-class#404: Allow calling Curl::getInfo() without option
1 parent 9ad5458 commit ed37de7

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Curl::error($callback)
201201
Curl::exec($ch = null)
202202
Curl::get($url, $data = array())
203203
Curl::getCookie($key)
204-
Curl::getInfo($opt)
204+
Curl::getInfo($opt = null)
205205
Curl::getOpt($option)
206206
Curl::getResponseCookie($key)
207207
Curl::head($url, $data = array())

src/Curl/Curl.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,16 @@ public function get($url, $data = array())
422422
*
423423
* @return mixed
424424
*/
425-
public function getInfo($opt)
425+
public function getInfo($opt = null)
426426
{
427-
return curl_getinfo($this->curl, $opt);
427+
$args = array();
428+
$args[] = $this->curl;
429+
430+
if (func_num_args()) {
431+
$args[] = $opt;
432+
}
433+
434+
return call_user_func_array('curl_getinfo', $args);
428435
}
429436

430437
/**

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,4 +3000,45 @@ public function testUnsetHeader()
30003000
$curl->get(Test::TEST_URL, $data);
30013001
$this->assertEquals('', $curl->response);
30023002
}
3003+
3004+
public function testGetInfo()
3005+
{
3006+
$test = new Test();
3007+
$test->server('server', 'GET');
3008+
$info = $test->curl->getInfo();
3009+
3010+
$expected_keys = array(
3011+
'url',
3012+
'content_type',
3013+
'http_code',
3014+
'header_size',
3015+
'request_size',
3016+
'filetime',
3017+
'ssl_verify_result',
3018+
'redirect_count',
3019+
'total_time',
3020+
'namelookup_time',
3021+
'connect_time',
3022+
'pretransfer_time',
3023+
'size_upload',
3024+
'size_download',
3025+
'speed_download',
3026+
'speed_upload',
3027+
'download_content_length',
3028+
'upload_content_length',
3029+
'starttransfer_time',
3030+
'redirect_time',
3031+
'certinfo',
3032+
'primary_ip',
3033+
'primary_port',
3034+
'local_ip',
3035+
'local_port',
3036+
'redirect_url',
3037+
'request_header',
3038+
);
3039+
3040+
foreach ($expected_keys as $key) {
3041+
$this->assertArrayHasKey($key, $info);
3042+
}
3043+
}
30033044
}

0 commit comments

Comments
 (0)