Skip to content

Allow casting CurlHandle to int #5743

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

Closed
wants to merge 1 commit into from
Closed

Conversation

nikic
Copy link
Member

@nikic nikic commented Jun 19, 2020

It's common to cast curl resources to integer to get the resource ID. This allows casting the new CurlHandle object to int as well, returning the object ID. This seems like a simple way to improve compatibility with PHP 7.

Something to keep in mind is that unlike resource IDs, object IDs are reused.

I'm only doing this for CurlHandle, not CurlMultiHandle or CurlShareHandle. Do those need this as well?

cc @kocsismate @nicolas-grekas

@KalleZ
Copy link
Member

KalleZ commented Jun 19, 2020

Since we are changing from resources to objects, making is_resource calls into is_object and get_resource_type into instanceof, wouldn't it make sense not to do this? As the CurlHandle would be the only class to have such behavior, possibly because it is the most commonly used one, none of the other resource > object conversions do this (unless I missed it)

@nikic
Copy link
Member Author

nikic commented Jun 19, 2020

@KalleZ The other resource conversions indeed don't do this, but I would expect us to do this for other cases where it's common, e.g. if we switch streams to use objects.

is_resource() checks are not replaced with is_object() checks, they're replaced with !== false checks that work on PHP 7 and PHP 8. For the int cast, one would have to use something like

$map[\is_resource($curl) ? (int) $curl : \spl_object_id($curl)] = $curl;

instead. Which is not particularly bad of course, but also not ideal.

@kocsismate
Copy link
Member

@nikic Thank you for the fix! I wouldn't have had the time for this now.

If we are talking about improvements related to migrated objects.. It would be nice to also lock these classes via #5572 . Or is there any problem/question that prevents you from committing it?

nikic referenced this pull request Jun 19, 2020
Closes GH-5402

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
@php-pulls php-pulls closed this in 1c4463c Jun 19, 2020
@nikic
Copy link
Member Author

nikic commented Jun 19, 2020

I went ahead and landed this to avoid unnecessary disruption. Happy to revert if we don't have a consensus (though per chat, it seems we do).

@GrahamCampbell
Copy link
Contributor

Nice. 🎉

@derrabus
Copy link
Contributor

This mechanism currently seems to work for CurlHandle instances, but not for CurlMultiHandle instances. Is this intended?

@kocsismate
Copy link
Member

@derrabus It's written in the description:

I'm only doing this for CurlHandle, not CurlMultiHandle or CurlShareHandle. Do those need this as well?

@GrahamCampbell
Copy link
Contributor

Do those need this as well?

It seems the answer is, yes. ;)

@nikic
Copy link
Member Author

nikic commented Jun 22, 2020

Can you point me to some piece of code that does this for a curl multi handle?

@derrabus
Copy link
Contributor

@nikic
Copy link
Member Author

nikic commented Jun 22, 2020

@derrabus Thanks, I've applied 26171c3.

@derrabus
Copy link
Contributor

@nikic Wow, thanks a lot for the quick patch. ❤️

@carusogabriel carusogabriel added this to the PHP 8.0 milestone Jul 23, 2020
megaelk added a commit to megaelk/mainwp that referenced this pull request Jan 30, 2021
[PHP8 Testing] curl objects are no longer resources in PHP8, rather CurlHandle object type. Casting CurlHandle as (int) returns handle id.

php/php-src#5743
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.

6 participants