PHP: curl_init() giving NULL although created the resource
I'm facing an error:
Warning: curl_exec() expects parameter 1 to be resource, null given in
$json_string = curl_exec($variable_curl);
I'm not sure what was wrong. I have
function __construct() {
$variable_curl = curl_init(); //Create a new cURL resource
}
I've confirmed the curl binding is working correctly because I used it without creating a library.
Based on that error, I can only tell $variable_curl wasn't created as a cURL resource corre开发者_运维技巧ctly/non at all. But by looking at the function __construct
above, I've done it.
Is $variable_curl
a global variable? If not, it won't be visible outside of your constructor. If so, you need to declare it as such inside the function:
global $variable_curl;
精彩评论