PHP 7.4.1 - PECL is not working (Trying to access array offset on value of type bool in PEAR/REST.php on line 181) [closed]
Asked Answered
C

3

21

Since PHP 7.4.1 there is pear error with the newest version even though they said its fixed.

Example: if you try to install any package using the "pecl" a warning error returns with the message:

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

The repositories have already been updated, but the problem persists

Cumulous answered 13/1, 2020 at 16:42 Comment(2)
which pear version are you using? where is stated that your bug is fixed there?Untold
I'm having the same issue with PEAR Version: 1.10.10 PHP Version: 7.4.2 MAC OS 10.14.6 (Mojave)Tantara
O
30

I had the same issue and creating the temporary pear cache directory solved it.

mkdir -p /tmp/pear/cache
Oestrone answered 26/3, 2020 at 6:48 Comment(1)
but new error occur. enable igbinary serializer support? [no] : no Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in Builder.php on line 40Ritz
M
10

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);
        }
Montford answered 16/1, 2020 at 19:58 Comment(0)
U
1

I met with the same problem while trying to install xdebug using PECL. Something about that code block that you quoted is causing problems. I think that's a problem somehow related to MacOS Catalina, saw three people with that error and all were using newest MacOS.

As a workaround I commented the 'if' block that you quoted. That seems to get the job done, as I could install xdebug normally after doing that.

Underdog answered 23/1, 2020 at 23:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.