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

Object of class CurlHandle could not be converted to string on php 8 #5

Open
AdiPP opened this issue Aug 7, 2022 · 0 comments
Open

Comments

@AdiPP
Copy link

AdiPP commented Aug 7, 2022

I got this error when curl session failed on PHP 8.

Error: Object of class CurlHandle could not be converted to string in /srv/app/vendor/lokielse/aliyun-open-api-sls/src/Requests/RequestCore.php:664
Stack trace:
#0 /srv/app/vendor/lokielse/aliyun-open-api-sls/src/Client.php(355): Aliyun\SLS\Requests\RequestCore->send_request()
#1 /srv/app/vendor/lokielse/aliyun-open-api-sls/src/Client.php(311): Aliyun\SLS\Client->getHttpResponse()
#2 /srv/app/vendor/lokielse/aliyun-open-api-sls/src/Client.php(289): Aliyun\SLS\Client->sendRequest()
#3 /srv/app/vendor/lokielse/aliyun-open-api-sls/src/Client.php(231): Aliyun\SLS\Client->send()

After some debugs, this is because you try to parse the CurlHandle object to string directly. Check this out:

// RequestCore.php
// ...
// The problem happen on `(string) $curl_handle`
if ($this->response === false) {
	throw new Exception('[RequestCoreException] cURL resource: ' . (string) $curl_handle . '; cURL error: ' . curl_error($curl_handle) . ' (' . curl_errno($curl_handle) . ')');
}
// ...

It works on PHP 5 through 7, but doesn't work on PHP 8 and caused a parsing error. So I make this PR #4 to update it.

Anyway, in case you still wanna use some info from your CurlHandle object for the exception message, consider using curl_getinfo. Based on PHP Doc, it comply with PHP 4 >= 4.0.4, PHP 5, PHP 7, and PHP 8.

@AdiPP AdiPP changed the title Object of class CurlHandle could not be converted to string on php 8.* Object of class CurlHandle could not be converted to string on php 8 Aug 7, 2022
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

No branches or pull requests

1 participant