Doc #64507 [NEW]: CURLOPT_*FUNCTION options accept closures but documentation says otherwise
| From: | vandry at TZoNE dot ORG | Date: | Mon, 25 Mar 2013 05:54:31 +0000 |
| Subject: | Doc #64507 [NEW]: CURLOPT_*FUNCTION options accept closures but documentation says otherwise | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-9691@lists.php.net to get a copy of this message | ||
From: vandry at TZoNE dot ORG
Operating system: Ubuntu/Linux
PHP version: Irrelevant
Package: cURL related
Bug Type: Documentation Problem
Bug description:CURLOPT_*FUNCTION options accept closures but documentation says otherwise
Description:
------------
libcurl accepts callback functions for various events, such as a handle
receiving data. The documentation says:
"value should be a string that is the name of a valid callback function"
Actually, curl_setopt() also accepts a closure for these options, as shown
by the test script supplied in this report.
A closure or anonymous function, not a string containing the name of a
function, should in fact be the recommended way to set these options. A
string name is (presumably) looked up in the PHP script's global scope and
such a function cannot access any state information from the local scope of
the caller of curl_setopt(), making that much less useful.
Test script:
---------------
function do_a_curl_thing() {
$handle = curl_init();
$some_state_information = "foobar";
curl_setopt($handle, CURLOPT_URL, "http://www.php.net");
curl_setopt(
$handle,
CURLOPT_WRITEFUNCTION,
function($res, $data) use ($some_state_information) {
echo "do something with the data that came in " . $data;
echo "while possibly consulting or mutating ";
echo $some_state_information;
}
);
curl_exec($handle);
}
do_a_curl_thing();
Expected result:
----------------
The documentation should state:
value should be a valid callback function, specified either directly as a
closure or anonymous function, or as a string that is the name of such a
function. Specifying a function directly is recommended.
Actual result:
--------------
The documentation states:
value should be a string that is the name of a valid callback function
--
Edit bug report at https://bugs.php.net/bug.php?id=64507&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64507&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64507&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64507&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=64507&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=64507&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=64507&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=64507&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=64507&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=64507&r=support
Expected behavior: https://bugs.php.net/fix.php?id=64507&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=64507&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=64507&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=64507&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64507&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=64507&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=64507&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=64507&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64507&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=64507&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=64507&r=mysqlcfg