|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-05-20 22:04 UTC] felipe@php.net
-Summary: CURLOPT_RETURNTRANSFER] returns both boolean and
response
+Summary: CURLOPT_RETURNTRANSFER returns both boolean and
response
[2012-09-22 14:42 UTC] pierrick@php.net
-Status: Open
+Status: Feedback
[2012-09-22 14:42 UTC] pierrick@php.net
[2013-02-18 00:35 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 04:00:01 2025 UTC |
Description: ------------ When calling a API and converting the response to an associative array, the returned response can not be converted because of the extra boolean in the response. Only viewable when exit($response) The options of the cURL operation are set using the @curl_setopt_array($ch, $array). When checked for the header, it does not indicate any problem and it outputs the correct content (with content length) When dumped the boolean is dumped with the correct response. Test script: --------------- // check if curl is available if(!function_exists('curl_init')) throw new Exception('This method requires cURL (http://php.net/curl), it seems like the extension isn\'t installed.'); $url = 'http://ws.audioscrobbler.com/2.0/?method=album.getbuylinks&artist=radiohead&album=in%20rainbows&country=united%20kingdom&api_key=b25b959554ed76058ac220b7b2e0a026&format=json'; // set options // $options[CURLOPT_URL] = (string) $url; // $options[CURLOPT_USERAGENT] = 'PlonkHTTP '. self::version; // $options[CURLOPT_FOLLOWLOCATION] = true; // $options[CURLOPT_RETURNTRANSFER] = true; // $options[CURLOPT_TIMEOUT] = 20; // $options[CURLOPT_HEADER] = true; // init $curl = @curl_init(); // @curl_setopt_array($curl, $options); curl_setopt($curl,CURLOPT_URL, (string) $url); curl_setopt($curl,CURLOPT_USERAGENT,'PlonkHTTP'); curl_setopt($curl,CURLOPT_RETURNTRANSFER, true); // execute $response = @curl_exec($curl); // fetch errors $errorNumber = @curl_errno($curl); $errorMessage = @curl_error($curl); // close @curl_close($curl); Expected result: ---------------- The script will result in a decent response on a local webserver. In a production environment, it gives the extra boolean when outputted. Actual result: -------------- http://ws.audioscrobbler.com/2.0/?method=album.getbuylinks&artist=radiohead&album=in%20rainbows&country=united%20kingdom&api_key=b25b959554ed76058ac220b7b2e0a026&format=json