[php-src] Issue #10387: can we make curl_close() write CURLOPT_COOKIEJAR again?
| From: | divinity76 | Date: | Fri, 20 Jan 2023 13:26:38 +0000 |
| Subject: | [php-src] Issue #10387: can we make curl_close() write CURLOPT_COOKIEJAR again? | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243508@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10387
Author: divinity76
### Description
The following code:
```php
<?php
declare(strict_types=1);
$ch = curl_init();
$cookiefile_handle = tmpfile();
$cookiefile = stream_get_meta_data($cookiefile_handle)['uri'];
curl_setopt_array($ch, array(
CURLOPT_COOKIEFILE => $cookiefile,
CURLOPT_COOKIEJAR => $cookiefile,
CURLOPT_WRITEFUNCTION => function ($ch, $str) {
// echo $str;
return strlen($str);
},
));
curl_setopt($ch, CURLOPT_URL, "https://example.com/");
curl_exec($ch);
var_dump(file_get_contents($cookiefile));
curl_close($ch);
var_dump(file_get_contents($cookiefile));
```
will, prior to PHP8.0.0 result in:
```
$ php7.4 test.php
string(0) ""
string(131) "# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
```
and in >=8.0.0 result in
```
$ php8.2 test.php
string(0) ""
string(0) ""
```
which breaks scripts relying on curl_close() writing to CURLOPT_COOKIEJAR
- either we should make curl_close write to COOKIEJAR again, or we should at least add a note to https://www.php.net/manual/en/migration80.incompatible.php
that you can no longer rely on curl_close to write to COOKIEJAR.
### PHP Version
PHP 8.0.0
### Operating System
_No response_