Thomas
Thomas

Reputation: 1354

PHP 8.4.1 : Constant E_STRICT is deprecated in pearcmd.php on line 441

I've upgraded php from 8.3 to PHP8.4.1_1 (via Homebrew on mac OS X intel), then I started to have a lot of warnings when using PECL/PEAR, while I was using PECL to install GRPC/PROTOBUF/MONGODB extension.

#pecl uninstall grpc protobuf
Deprecated: Constant E_STRICT is deprecated in /usr/local/Cellar/php/8.4.1_1/share/pear/pearcmd.php on line 441 PHP                                 
Deprecated:  Constant E_STRICT is deprecated in /usr/local/Cellar/php/8.4.1_1/share/pear/pearcmd.php on line 441

Apparently, since PHP 8.4, the E_STRICT keyword is deprecated from the PHP language, unfortunately, PEAR code is not up to date and still use this E_STRICT keyword.

I've also forced update pear to be sure to have the very last version of pear, without any effect on this issue.

curl -O https://pear.php.net/go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar

Upvotes: 1

Views: 3700

Answers (2)

Thomas
Thomas

Reputation: 1354

I've edited the pearcmd.php file to remove the use of this keyword :

sudo vi /usr/local/Cellar/php/8.4.1_1/share/pear/pearcmd.php

Here is the function with the comments (#) so that you can see the two parts that I've edited:

function error_handler($errno, $errmsg, $file, $line)
{
#    if ($errno & E_STRICT) {
#        return; // E_STRICT
#    }
    if ($errno & E_DEPRECATED) {
        return; // E_DEPRECATED
    }
    if (!(error_reporting() & $errno) &&
        isset($GLOBALS['config']) &&
        $GLOBALS['config']->get('verbose') < 4
    ) {
        return false; // @silenced error, show all if debug is high enough
    }
    $errortype = array (
        E_DEPRECATED  => 'Deprecated Warning',
        E_ERROR   =>  "Error",
        E_WARNING   =>  "Warning",
        E_PARSE   =>  "Parsing Error",
#        E_STRICT  => 'Strict Warning',
        E_NOTICE   =>  "Notice",
        E_CORE_ERROR  =>  "Core Error",
        E_CORE_WARNING  =>  "Core Warning",
        E_COMPILE_ERROR  =>  "Compile Error",
        E_COMPILE_WARNING =>  "Compile Warning",
        E_USER_ERROR =>  "User Error",
        E_USER_WARNING =>  "User Warning",
        E_USER_NOTICE =>  "User Notice"
    );
    $prefix = $errortype[$errno];
    global $_PEAR_PHPDIR;
    if (stristr($file, $_PEAR_PHPDIR)) {
        $file = substr($file, strlen($_PEAR_PHPDIR) + 1);
    } else {
        $file = basename($file);
    }
    print "\n$prefix: $errmsg in $file on line $line\n";
    return false;
}

Dirty fix, but it's really unusable in the current state, and worth doing while waiting pear fix this : https://github.com/pear/pear-core/issues/148

Upvotes: 0

IMSoP
IMSoP

Reputation: 97948

Deprecations are not something you, or anyone else, needs to fix Right Now. They are indications that in the future, an error will happen here.

At the moment, it is likely there will be a PHP 8.5 before PHP 9.0, so you have two years before these deprecations become errors.

If you see deprecations in your own code, you should make time over the next couple of years to modernise it.

If you see deprecations in other people's code, you have two options:

  1. Be patient. If the package is actively maintained, someone will probably update it in due course.
  2. Contribute a fix yourself. Most free software / open source libraries are happy to have contributions, as long as they are clearly documented and tested.

In this case, I believe the repository you could contribute a fix to is here: https://github.com/pear/pear-core

However, note that PEAR and PECL are very old code bases, and it's possible they will be replaced completely before PHP 9.0. Most PEAR packages can already be installed via Composer and a replacement for PECL is under development called PIE.

Upvotes: 2

Related Questions