Skip to content

Commit

Permalink
Merge pull request #94 from oleg-andreyev/unify-getcacheid
Browse files Browse the repository at this point in the history
Updated logic in useLocalCache to reuse getCacheId
  • Loading branch information
ashnazg authored Nov 19, 2019
2 parents e278a34 + 6fec49a commit e28643e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions PEAR/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,7 @@ function retrieveData($url, $accept = false, $forcestring = false, $channel = fa
function useLocalCache($url, $cacheid = null)
{
if (!is_array($cacheid)) {
$cacheidfile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
md5($url) . 'rest.cacheid';
if (!file_exists($cacheidfile)) {
return false;
}

$cacheid = unserialize(implode('', file($cacheidfile)));
$cacheid = $this->getCacheId($url);
}

$cachettl = $this->config->get('cache_ttl');
Expand All @@ -191,6 +185,11 @@ function useLocalCache($url, $cacheid = null)
return false;
}

/**
* @param string $url
*
* @return bool|mixed
*/
function getCacheId($url)
{
$cacheidfile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
Expand Down

1 comment on commit e28643e

@arjendekorte
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commits results in the following error for each 'url' not in the cache:

Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 181
PHP Notice: Trying to access array offset on value of type bool in /usr/share/php7/PEAR/PEAR/REST.php on line 181

This is because the getCacheId will return 'false' in this case and this is not caught before using cacheid['age'].

Please sign in to comment.