![](/img/trans.png)
[英]PHP Error - Warning: count(): Parameter must be an array or an object that implements Countable
[英]PHPgraphlib PHP Warning count() Parameter must be an Array or Object (line 926)
我使用 PHPgraphlib 多年,並且喜歡它生成可靠的圖像而不是一些花哨的 Javascript 東西。 現在自從更新到 PHP7 后,它在原始代碼的第 926 行呈現了一個日志錯誤:
PHP Warning: count(): Parameter must be an array or object that implements Countable in ./phpgraphlib.php on line 926, referrer ...
從第 926 行開始:
protected function displayErrors()
{
if (count($this->error) > 0) {
$lineHeight = 12;
$errorColor = imagecolorallocate($this->image, 0, 0, 0);
$errorBackColor = imagecolorallocate($this->image, 255, 204, 0);
imagefilledrectangle($this->image, 0, 0, $this->width - 1, 2 * $lineHeight, $errorBackColor);
imagestring($this->image, 3, 2, 0, "!!----- PHPGraphLib Error -----!!", $errorColor);
foreach($this->error as $key => $errorText) {
imagefilledrectangle($this->image, 0, ($key * $lineHeight) + $lineHeight, $this->width - 1, ($key * $lineHeight) + 2 * $lineHeight, $errorBackColor);
imagestring($this->image, 2, 2, ($key * $lineHeight) + $lineHeight, "[". ($key + 1) . "] ". $errorText, $errorColor);
}
$errorOutlineColor = imagecolorallocate($this->image, 255, 0, 0);
imagerectangle($this->image, 0, 0, $this->width-1,($key * $lineHeight) + 2 * $lineHeight, $errorOutlineColor);
}
}
我試圖取消注釋它,但它在第 271 行引發了另一個錯誤
//display errors
$this->displayErrors();
我用 PHP 和 MySQL 做了很多,但這超出了我的業余知識。 歡迎任何幫助,除了這個錯誤。 phpgraphlib 一直像魅力一樣工作,我使用了錯誤。 因為我在 phpgraphlib 上找不到任何搜索此錯誤的內容。 歡迎參考回答的地方。
太感謝了!
正如@aynber 所評論的那樣——將 =[] 添加到 protected $error; 在第 137 行成功了。 新行讀取
protected $error = [];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.