当前位置: 首页 > 知识库问答 >
问题:

PHP警告:参数必须是使用xampp实现可数的数组或对象

洪成济
2023-03-14

我尝试使用xampp运行php程序,但它显示以下错误:

参数必须是实现Countable的数组或对象。

显示错误的代码部分如下所示:

    if (count($this->handles) >= $this->maxHandles) {
        curl_close($resource);
    } else {
        // Remove all callback functions as they can hold onto references
        // and are not cleaned up by curl_reset. Using curl_setopt_array
        // does not work for some reason, so removing each one
        // individually.
        curl_setopt($resource, CURLOPT_HEADERFUNCTION, null);
        curl_setopt($resource, CURLOPT_READFUNCTION, null);
        curl_setopt($resource, CURLOPT_WRITEFUNCTION, null);
        curl_setopt($resource, CURLOPT_PROGRESSFUNCTION, null);
        curl_reset($resource);
        $this->handles[] = $resource;
    }

共有2个答案

董翰池
2023-03-14

php中的count()方法

Warning: count(): Parameter must be an array or an object that implements Countable in … on line..

php8中的该项:

Fatal error: Uncaught TypeError: count(): Argument # 1 ($var) must be of type Countable...

因此,在使用count()方法检查之前,可以先检查可计数类型是否无效。(例如,根据需要,在此之前使用empty()方法,或给出空数组值或…)或使用is_数组is_对象或。。。

7.2.0 count()现在将对传递给value参数的无效可数类型发出警告。

孙思源
2023-03-14

首先检查如果$this-

if(is_array($this->handles) || is_object($this->handles))
{
        if (count($this->handles) >= $this->maxHandles) {
        curl_close($resource);
    } else {
        // Remove all callback functions as they can hold onto references
        // and are not cleaned up by curl_reset. Using curl_setopt_array
        // does not work for some reason, so removing each one
        // individually.
        curl_setopt($resource, CURLOPT_HEADERFUNCTION, null);
        curl_setopt($resource, CURLOPT_READFUNCTION, null);
        curl_setopt($resource, CURLOPT_WRITEFUNCTION, null);
        curl_setopt($resource, CURLOPT_PROGRESSFUNCTION, null);
        curl_reset($resource);
        $this->handles[] = $resource;
    }
}
else
{
    echo $this->handles." isn't a array or object";
}
 类似资料: