安装pcov遇到的问题

pcov

用于PHP的自包含CodeCoverage兼容驱动程序,安装源代码

安装步骤

git clone https://github.com/krakjoe/pcov.git
cd pcov
phpize
./configure --enable-pcov
make
make test
make install

image-20221009233245745image-20221009233327132

在安装好之后运行pecl install pecv时遇到了一些问题,首先是

image-20221009233446567

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了。

image-20221009234535867

posted @ 2022-10-09 23:50  ivanlee717  阅读(54)  评论(0编辑  收藏  举报