doc-en icon indicating copy to clipboard operation
doc-en copied to clipboard

curl-close.xml: Add a hint on how to destroy the cURL handle

Open mmalferov opened this issue 1 year ago • 1 comments

I know that the cURL handle is now an instance of the CurlHandle class. I also know that we can free up resources by deleting an object through the unset() language construct. Maybe the mention of unset() is redundant. But something tells me that the curl_close() page violates the principle: Rejecting — offer! The page warned that the curl_close() function is a no-op as of PHP 8.0.0, but did not offer an alternative (at least in the code example).

What do dear colleagues think about this?

mmalferov avatar Jul 28 '24 01:07 mmalferov

Well, it's not really about unsetting the variable, but rather about the refcount of the object; when the latter decreases to zero, the object is released. For the given code examples, unset($ch) works the same like $ch = null or even $ch = "bye" would. And if these examples are used stand-alone, there is even no need for this (at the end of the script, global variables get their refcount decreased, anyway). Same if the code snippets were the body of a function. But just adding something like $ch1 = $ch somewhere in the middle of these examples, will not release the object when unset($ch) is called.

I think that users must understand the refcount principle, and also what happens when a certain object is released (i.e. what's happening in __destruct(), basically). Whether a hint at unset() helps them to be reminded of that – I don't know.

cmb69 avatar Jul 28 '24 09:07 cmb69

Thank you, but I disagree. We should not recommend using unset in this place. It's not the PHP way. curl_close should not be replaced with anything.

kamil-tekiela avatar Dec 03 '24 15:12 kamil-tekiela