pcov
用于PHP的自包含CodeCoverage兼容驅動程式,安裝源代碼
安裝步驟
git clone https://github.com/krakjoe/pcov.git
cd pcov
phpize
./configure --enable-pcov
make
make test
make install


在安裝好之后運行pecl install pecv時遇到了一些問題,首先是

Trying to access array offset on value of type bool in PEAR/REST.php on line 187
這個報錯的意思是:嘗試訪問型別為 null 的值的陣列偏移量,就是說有個變成為nul導致了報錯,php版本為7.4的時候才出現了這個錯誤,我們翻回去看看原始碼的樣子
function useLocalCache($url, $cacheid = null)
{
if ($cacheid === null) {
$cacheidfile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
md5($url) . 'rest.cacheid';
if (!file_exists($cacheidfile)) {
return false;
}
$cacheid = unserialize(implode('', file($cacheidfile)));
}
$cachettl = $this->config->get('cache_ttl');
// If cache is newer than $cachettl seconds, we use the cache!
if (time() - $cacheid['age'] < $cachettl) {
return $this->getCache($url);
}
return false;
}
首先我們注意到函式的形參有一個默認值$cacheid = null,然后在第14行的時候呼叫了這一個函式,但是我們注意到形參中是一個空值,但呼叫的時候當快取檔案不存時,getCacheId將回傳false,那第14行試圖訪問陣列偏移量false,不存在就當然會報錯了,所以我們需要提前加一個判斷,如果$cacheid存在,我們才可以訪問,
if ($cacheid && time() - $cacheid['age'] < $cachettl) {
return $this->getCache($url);
}
然后再運行看看
parallels@parallels-Parallels-Virtual-Platform:~/pcov$ pecl install pcov
Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user
這個比較容易,給提個權限就ok了,

本文來自博客園,作者:ivanlee717,轉載請注明原文鏈接:https://www.cnblogs.com/ivanlee717/p/16774166.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/511966.html
標籤:其他
上一篇:代碼隨想錄 | 二叉樹的遍歷
