Skip to content

php8.1删除文件会报错 #390

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
cgfeel opened this issue Aug 4, 2022 · 4 comments
Closed

php8.1删除文件会报错 #390

cgfeel opened this issue Aug 4, 2022 · 4 comments

Comments

@cgfeel
Copy link

cgfeel commented Aug 4, 2022

PHP Deprecated:  strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /app/api_service/vendor/qiniu/php-sdk/src/Qiniu/Auth.php on line 125

错误原因是调用signQiniuAuthorization的时候,$body传参null,导致strlen($body) > 0时出现问题

麻烦修传$body的时候用$body?:'',或者兼容写法$body ? $body : ''

PHP版本: 8.1.1

@cgfeel
Copy link
Author

cgfeel commented Aug 4, 2022

同样获取文件列表也会出现同样的错误
以获取文件列表为例,这段代码会传入auth对象,并调用listFiles

$bucketManager = new BucketManager($this->_auth);
$bucketManager->listFiles($this->_bucket, $prefix, $marker, $limit, $delimiter);
  • BucketManager中通过getV2来获取列表
  • getV2会执行authauthorizationV2,应该是进行验证操作的方法,这里传入了null
return $this->getV2($url);
// ...
$headers = $this->auth->authorizationV2($url, 'GET', null, 'application/x-www-form-urlencoded');

以上都没问题,因为authorizationV2body默认参数类型就是null,有问题的在于在authorizationV2中调用signQiniuAuthorization也传入了默认的bodynull

list($sign) = $this->signQiniuAuthorization($url, $method, $body, $headers);

而在signQiniuAuthorization中进行了strlen判断报错strlen($body) > 0,正确的做法,应该是

list($sign) = $this->signQiniuAuthorization($url, $method, $body?:'', $headers);

或者向下兼容写法

list($sign) = $this->signQiniuAuthorization($url, $method, $body ? $body : '', $headers);

@cgfeel
Copy link
Author

cgfeel commented Aug 4, 2022

除此之外,如果是第一次请求,还会有一堆错误,我就不一一列举了

PHP Deprecated:  Return type of Qiniu\Http\Header::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/api_service/vendor/qiniu/php-sdk/src/Qiniu/Http/Header.php on line 114
PHP Deprecated:  Return type of Qiniu\Http\Header::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/api_service/vendor/qiniu/php-sdk/src/Qiniu/Http/Header.php on line 125
PHP Deprecated:  Return type of Qiniu\Http\Header::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/api_service/vendor/qiniu/php-sdk/src/Qiniu/Http/Header.php on line 141
PHP Deprecated:  Return type of Qiniu\Http\Header::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/api_service/vendor/qiniu/php-sdk/src/Qiniu/Http/Header.php on line 154
PHP Deprecated:  Return type of Qiniu\Http\Header::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/api_service/vendor/qiniu/php-sdk/src/Qiniu/Http/Header.php on line 163
PHP Deprecated:  Return type of Qiniu\Http\Header::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/api_service/vendor/qiniu/php-sdk/src/Qiniu/Http/Header.php on line 175
TypeError: Qiniu\Auth::signQiniuAuthorization(): Argument #3 ($body) must be of type string, null given, called in /app/api_service/vendor/qiniu/php-sdk/src/Qiniu/Auth.php on line 250

@tianyiw2013
Copy link

#388

@cgfeel
Copy link
Author

cgfeel commented Aug 5, 2022

#388

感谢

@cgfeel cgfeel closed this as completed Aug 5, 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

2 participants