Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mmalferov
Copy link
Member

@mmalferov mmalferov commented Jul 28, 2024

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?

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?
@cmb69
Copy link
Member

cmb69 commented Jul 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants