I met the same issue.
Notice: Trying to access array offset on value of type bool in REST.php on line 181
PEAR Version: 1.10.1
PHP Version: 7.4.1
Zend Engine Version: 3.4.0
Running on: Darwin kairee-mbp 19.2.0 Darwin Kernel Version 19.2.0
function useLocalCache($url, $cacheid = null)
{
if (!is_array($cacheid)) {
$cacheid = $this->getCacheId($url);
}
$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;
}
/**
* @param string $url
*
* @return bool|mixed
*/
function getCacheId($url)
{
$cacheidfile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
md5($url) . 'rest.cacheid';
if (!file_exists($cacheidfile)) {
return false;
}
$ret = unserialize(implode('', file($cacheidfile)));
return $ret;
}
You may notice that when the cached file not exists, getCacheId
will return false
. In line 181, the code if (time() - $cacheid['age'] < $cachettl) {
is trying to access array offset on false
.
I add a condition to this line to fix it:
// If cache is newer than $cachettl seconds, we use the cache!
- if (time() - $cacheid['age'] < $cachettl) {
+ if ($cacheid && time() - $cacheid['age'] < $cachettl) {
return $this->getCache($url);
}