|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-03-25 08:24 UTC] krakjoe@php.net
[2013-03-25 08:24 UTC] krakjoe@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: krakjoe
[2013-03-25 08:24 UTC] krakjoe@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 25 06:00:01 2025 UTC |
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