Skip to content

PHP 8: Add support for CurlHandle resource objects #70

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

PHP 8: Add support for CurlHandle resource objects #70

wants to merge 1 commit into from

Conversation

Ayesh
Copy link

@Ayesh Ayesh commented Nov 21, 2020

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets fixes #X, partially #Y, mentioned in #Z
Documentation if this is a new feature, link to pull request in https://github.com/php-http/documentation that adds relevant documentation
License MIT

What's in this PR?

In PHP 8.0, Curl resources are changed to CurlHandle class objects. This changes DocBlock parameters and other areas where provided handles are checked with is_resource(), which now needs to account for the replaced CurlHandle class objects.

Why?

Because in PHP 8.0, Curl handles are no longer resources, and this libraries is_resource no longer return true for valid Curl handlers.

Example Usage

is_resource(curl_init()); // true in PHP < 8.0
is_resource(curl_init()); // false in PHP >= 8.0

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix
  • Documentation pull request created (if not simply a bugfix)

In PHP 8.0, [Curl resources are changed to CurlHandle class objects](https://php.watch/versions/8.0/resource-CurlHandle#is-resource). This changes DocBlock parameters and other areas where provided handles are checked with `is_resource()`, which now needs to account for the replaced `CurlHandle` class objects.
Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot for looking into this!

can you please adjust composer.json to allow ^7.1 || ^8.0? and add php 7.4 and 8.0 to the list of php versions in .travis.yml so that we see if it completely works?

@@ -80,7 +80,7 @@ public function __construct(
$handle,
ResponseBuilder $responseBuilder
) {
if (!is_resource($handle)) {
if (!is_resource($handle) && !(is_object($handle) && $handle instanceof \GdImage)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am confused by the second part, i assume you meant CurlHandle rather than GdImage?

but i think we should make an explicit check for the php version. something like

if (
    PHP_MAJOR_VERSION === 7 && !is_resource($handle)
    || PHP_MAJOR_VERSION > 7 && !$handle instanceof CurlHandle
) {
...

* @param resource $handle cURL handle.
* @param ResponseBuilder $responseBuilder Response builder.
* @param RequestInterface $request HTTP request.
* @param resource|CurlHandle $handle cURL handle.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param resource|CurlHandle $handle cURL handle.
* @param resource|\CurlHandle $handle cURL handle.

or add CurlHandle to the use classes

@@ -89,7 +89,7 @@ public function __construct(
);
}

if (get_resource_type($handle) !== 'curl') {
if (is_resource($handle) && get_resource_type($handle) !== 'curl') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for php version.

maybe we should split all checks into something like this?

if (PHP_MAJOR_VERSION === 7) {
    both checks
} else {
    class check
}

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