As I was following the instructions on how to install PEAR from the official [manual,][1] and got this error:
Fatal error: Uncaught Error: Failed opening required 'phar://go-pear.phar/index.php' (include_path='C:\xampp_latest\php\PEAR') in C:\xampp_latest\php\go-pear.phar:1284 Stack trace: #0 {main} thrown in C:\xampp_latest\php\go-pear.phar on line 1284
I tried looking for other solutions and found [this][2]. However, I still couldn't install pear and still get this error:
PHP Fatal error: Array and string offset access syntax with curly braces is no longer supported in C:\xampp_latest\php\go-pear.php on line 1182.
I tried the installation via webbased and command line, but got the same error.
Just another update.. I went ahead and searched even more and got to this: link So I tried to change the curly braces into square brackets from different files as suggested from the errors, and at 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_latest\php\pear\pearcmd.php:446
Stack trace:
#0 [internal function]: error_handler(8192, 'trim(): Passing...', 'C:\\xampp_latest...', 152)
#1 C:\xampp_latest\php\pear\PEAR\XMLParser.php(152): trim(NULL)
#2 C:\xampp_latest\php\pear\PEAR\XMLParser.php(166): PEAR_XMLParser->postProcess(NULL, 'options')
#3 [internal function]: PEAR_XMLParser->endHandler(Object(XMLParser), 'options')
#4 C:\xampp_latest\php\pear\PEAR\XMLParser.php(102): xml_parse(Object(XMLParser), '<commands versi...')
#5 C:\xampp_latest\php\pear\PEAR\Command.php(247): PEAR_XMLParser->parse('<commands versi...')
#6 C:\xampp_latest\php\pear\PEAR\Command.php(302): PEAR_Command::registerCommands()
#7 C:\xampp_latest\php\pear\pearcmd.php(54): PEAR_Command::getCommands()
#8 {main}
thrown in C:\xampp_latest\php\pear\pearcmd.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/
Basically the PEAR provided with xampp is not updated to run under PHP 8.x. and is facing to several deprecated and removed features in PHP 8.0 that cause the PHP Fatal errors.
1) Accessing characters issue
The first problem is with strings access by the zero-based offset when access using curly brackets
{}was removed and only square brackets[]can be used.Compare original code
with fixed code:
Solution:
Search all files in your
xampp/php/pearfolder with regular expression\{(\$[a-zA-Z0-9\+]*)\}and replace it with[$1]IMPORTANT: review each occurrence not to alter regex expressions in the scripts!!!
2) Uncaught ArgumentCountError issue
The second problem is with php function set_error_handler where was removed last param in PHP 8.0.0.
The call back function expects five params however it gets only four params and therefore the call fails with
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function error_handler(), 4 passed and exactly 5 expected.Solution:
Search for the
set_error_handler(calls and find the refereed call back functionerror_handlerand make the last param optional.In my case it was in script
xampp\php\pear\pearcmd.phpand the function definition was on line 446:Compare original function definition:
with applied fix:
Note: I found that "bug" has been already reported on the Apache Friends Support Forum already back in September 2021..
3) Undefined function each() issue
The third problem is is with removed PHP function each() that is throwing
PHP Fatal error: Uncaught Error: Call to undefined function each().Solution
Search for all occurrences of
each((use the space to eliminate function 'foreach' in the result set) and review and update it with functionforeachwith proper params used in each file. \An example of
whilesyntaxcan be replaced with
An example of
listsyntaxcan be replaced with
There are some other cases used in
If - elsestatements that can be replaced byemtpy($args)followed byforeach($args as $opt_arg){}to build the variable $opt_arg.An example of
If - elsesyntaxcan be replaced with
And PEAR is finally working with XAMPP Version: 8.2.0