Doc #64507 [Opn->Csd]: CURLOPT_*FUNCTION options accept closures but documentation says otherwise

From: Date: Mon, 25 Mar 2013 08:24:23 +0000
Subject: Doc #64507 [Opn->Csd]: CURLOPT_*FUNCTION options accept closures but documentation says otherwise
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9692@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64507&edit=1 ID: 64507 Updated by: krakjoe@php.net Reported by: vandry at TZoNE dot ORG Summary: CURLOPT_*FUNCTION options accept closures but documentation says otherwise -Status: Open +Status: Closed Type: Documentation Problem Package: cURL related Operating System: Ubuntu/Linux PHP Version: Irrelevant -Assigned To: +Assigned To: krakjoe Block user comment: N Private report: N New Comment: The fix for this bug has been committed. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. For Windows: http://windows.php.net/snapshots/ Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2013-03-25 08:24:06] krakjoe@php.net Automatic comment from SVN on behalf of krakjoe Revision: http://svn.php.net/viewvc/?view=revision&revision=329914 Log: #64507 adjustments to wording ------------------------------------------------------------------------ [2013-03-25 05:54:31] vandry at TZoNE dot ORG 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 this bug report at https://bugs.php.net/bug.php?id=64507&edit=1

« previous php.doc.bugs (#9692) next »