Home  >  Q&A  >  body text

Pear installation in Windows XAMPP PHP 8.1.10

When I followed the instructions on how to install PEAR in the official [manual][1], I got this error:

Fatal error: Uncaught Error: Unable to open required 'phar://go-pear.phar/index.php' in C:xampp_latestphp (include_path='C:xampp_latestphpPEAR') go-pear .phar:1284 Stack trace: #0 {main} thrown in C:xampp_latestphpgo-pear.phar line 1284

I tried looking for other solutions and found [this][2]. However, I still cannot install pear and I still get this error:

PHP Fatal Error: C:xampp_latestphpgo-pear.php line 1182 Array and string offset access syntax with braces is no longer supported.

I tried installing via network and command line but got the same error.

Another update.. I continued searching some more and got this: association So I tried changing the braces to square brackets in different files as suggested in the error, and in the end I got this error:

PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function error_handler(), 4 passed and exactly 5 expected in C:xampp_latestphppearpearcmd.php:446
Stack trace:
#0 [internal function]: error_handler(8192, 'trim(): Passing...', 'C:\xampp_latest...', 152)
#1 C:xampp_latestphppearPEARXMLParser.php(152): trim(NULL)
#2 C:xampp_latestphppearPEARXMLParser.php(166): PEAR_XMLParser->postProcess(NULL, 'options')
#3 [internal function]: PEAR_XMLParser->endHandler(Object(XMLParser), 'options')
#4 C:xampp_latestphppearPEARXMLParser.php(102): xml_parse(Object(XMLParser), '<commands versi...')
#5 C:xampp_latestphppearPEARCommand.php(247): PEAR_XMLParser->parse('<commands versi...')
#6 C:xampp_latestphppearPEARCommand.php(302): PEAR_Command::registerCommands()
#7 C:xampp_latestphppearpearcmd.php(54): PEAR_Command::getCommands()
#8 {main}
  thrown in C:xampp_latestphppearpearcmd.php on line 446

  [1]: https://pear.php.net/manual/en/installation.getting.php
  [2]: https://www.ivankristianto.com/install-or-update-pear-on-xampp-for-windows/


P粉141911244P粉141911244316 days ago398

reply all(1)I'll reply

  • P粉222320176

    P粉2223201762024-01-01 00:19:35

    Basically, the PEAR provided by xampp has not been updated to run under PHP 8.x. and faced multiple deprecated and removed features in PHP 8.0 that resulted in PHP fatal errors.

    1) Access character problem
    The first problem is that string access uses curly brackets {} The zero-based offset when accessing has been removed and only square brackets []## can be used #.

    Compare original code

    $arg{0}

    Use fixed code:

    $arg[0]

    solution: Use regular expression
    \{(\$[a-zA-Z0-9\ ]*)\} to search all files in xampp/php/pear folder and replace with [$1]
    Important: Check every occurrence and do not change the regular expression in the script! ! !


    2) Uncaught ArgumentCountError problem The second problem is that the php function
    set_error_handler where is < /a>removed the last parameter in PHP 8.0.0. The callback function requires
    five arguments, but it only gets four arguments, so the call fails with PHP Fatal error: Uncaught ArgumentCountError: Too Fewarguments to function error_handler( ) , 4 items passed, exactly 5 items were expected.

    solution: Search for the
    set_error_handler( call and find the referenced callback function error_handler and make the last argument optional. In my case it was in the script
    xampp\php\pear\pearcmd.php and the function definition was on line 446:

    Compare original function definition:

    function error_handler($errno, $errmsg, $file, $line, $vars)

    After applying the fix:

    function error_handler($errno, $errmsg, $file, $line, $vars = null)

    Note: I discovered that a "bug" has been reported on the

    Apache Friends Support Forum is back in September 2021.


    3) Undefined function each() problem The third problem is that the PHP function
    each() is removed, which throws PHP Fatal Error: Uncaught Error: Call to undefined function each().

    solution Search for all occurrences of
    every( (use spaces to eliminate function "foreach" in the result set) and check and update with function foreach and use the correct parameter file in each .\

    while Syntax example

    while (list($i, $arg) = each($args)) {

    can be replaced with

    foreach ($args as $i => $arg) {

    list Syntax example

    list(,$first) = each($lines);

    can be replaced with

    foreach($lines as $first){}

    There are some other situations used in

    If - else statements, you can use emtpy($args) followed by foreach($args as $opt_arg){} Build variable $opt_arg.

    If - else Syntax example

    if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {

    can be replaced with

    if (!strlen($opt_arg) && !empty($args)) {
           foreach($args as $opt_arg){}

    PEAR finally works with XAMPP version: 8.2.0

    C:\xampp\php>pear help version
    PEAR Version: 1.10.1
    PHP Version: 8.2.0
    Zend Engine Version: 4.2.0
    Running on: Windows NT D5KGFJF 10.0 build 19045 (Windows 10) AMD64

    reply
    0
  • Cancelreply