安装pcov遇到的问题
  3dygdw7fVgD7 2023年11月01日 36 0

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

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
3dygdw7fVgD7