I’m trying to use the curl headerfunction opt from a class. I’ve tried putting the functions inside the class normally, but curl can’t find them that way. So I put them inside the function I need it in. Here’s the part of code that’s applicable:
$ht = array();
$t = array();
function htWrite($stream,$buffer)
{
$ht[] = $buffer;
return strlen($buffer);
}
function tWrite($stream,$buffer)
{
$t[] = $buffer;
return strlen($buffer);
}
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'htWrite');
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'tWrite');
When I put an echo statement in htWrite for the buffer, it echos out just fine. But if I do a print_r statement on $ht later, it says that it’s empty. Further investigation says that it’s creating its own $ht variable, because if I remove that line, $ht is null according to the function. So what can I do to fix this?
You need to look at how you can specify object methods as callbacks: