Skip to content

Commit 357da6b

Browse files
committed
Deprecate and ignore $version parameter of curl_version()
`curl_version()`[1] (of ext/curl) makes `curl_version_info()`[2] (of libcurl) available to PHP userland. The latter requires to pass an `age` argument which usually is `CURLVERSION_NOW`, so that the information returned by the runtime matches the declarations used during compile time. For C programs it is simply necessary to pass this information, and in rare occasions it might make sense to pass something else than `CURLVERSION_NOW`. curl.h notes: | The 'CURLVERSION_NOW' is the symbolic name meant to be used by | basically all programs ever that want to get version information. For the PHP binding, using a newer `age` than available at compile time will neither provide the PHP program more information, nor would using an older `age` have tangible benefits. We therefore deprecate the useless `$version` parameter, and if it is passed nonetheless, we use `CURLVERSION_NOW` instead of the supplied value, and raise a warning. [1] <https://www.php.net/manual/en/function.curl-version.php> [2] <https://curl.haxx.se/libcurl/c/curl_version_info.html>
1 parent addf2ad commit 357da6b

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ PHP NEWS
2828
(Pierrick)
2929
. Implemented FR #77711 (CURLFile should support UNICODE filenames). (cmb)
3030
. Deprecated CURLPIPE_HTTP1. (cmb)
31+
. Deprecated $version parameter of curl_version(). (cmb)
3132

3233
- Date:
3334
. Fixed bug #75232 (print_r of DateTime creating side-effect). (Nikita)

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ PHP 7.4 UPGRADE NOTES
4646
Previously the exception was only thrown on unserialization.
4747
. Using CURLPIPE_HTTP1 is deprecated, and is no longer supported as of cURL
4848
7.62.0.
49+
. The $version parameter of curl_version() is deprecated. If any value not
50+
equal to the default CURLVERSION_NOW is passed, a warning is raised and the
51+
parameter is ignored.
4952

5053
- Date:
5154
. Calling var_dump() or similar on a DateTime(Immutable) instance will no

ext/curl/interface.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,14 +1830,20 @@ static void curl_free_slist(zval *el)
18301830
PHP_FUNCTION(curl_version)
18311831
{
18321832
curl_version_info_data *d;
1833-
zend_long uversion = CURLVERSION_NOW;
1833+
zend_long uversion = -1;
18341834

18351835
ZEND_PARSE_PARAMETERS_START(0, 1)
18361836
Z_PARAM_OPTIONAL
18371837
Z_PARAM_LONG(uversion)
18381838
ZEND_PARSE_PARAMETERS_END();
18391839

1840-
d = curl_version_info(uversion);
1840+
if (uversion == CURLVERSION_NOW) {
1841+
php_error_docref(NULL, E_DEPRECATED, "the $version parameter is deprecated");
1842+
} else if (ZEND_NUM_ARGS() > 0) {
1843+
php_error_docref(NULL, E_WARNING, "$version argument ignored");
1844+
}
1845+
1846+
d = curl_version_info(CURLVERSION_NOW);
18411847
if (d == NULL) {
18421848
RETURN_FALSE;
18431849
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
curl_version(): error conditions
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('curl')) die('skip curl extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
curl_version(CURLVERSION_NOW);
10+
curl_version(0);
11+
?>
12+
===DONE===
13+
--EXPECTF--
14+
Deprecated: curl_version(): the $version parameter is deprecated in %s on line %d
15+
16+
Warning: curl_version(): $version argument ignored in %s on line %d
17+
===DONE===

0 commit comments

Comments
 (0)