php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #64507 CURLOPT_*FUNCTION options accept closures but documentation says otherwise
Submitted: 2013-03-25 05:54 UTC Modified: 2013-03-25 08:24 UTC
From: vandry at TZoNE dot ORG Assigned: krakjoe (profile)
Status: Closed Package: cURL related
PHP Version: Irrelevant OS: Ubuntu/Linux
Private report: No CVE-ID: None
 [2013-03-25 05:54 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-25 08:24 UTC] 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 08:24 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2013-03-25 08:24 UTC] krakjoe@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 12:01:32 2024 UTC