Reputation: 31
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/
Upvotes: 2
Views: 2785
Reputation: 2591
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.
In next steps you I will describe how I upgraded the PEAR libs in my instance of XAMPP to make it working with PHP 8.x:
1) Accessing characters issue
The first problem is with strings access by the zero-based offset when access by curly brackets {}
was removed and only square brackets []
can be used.
Accessing characters within string literals using the {} syntax has been deprecated in PHP 7.4. This has been removed in PHP 8.0.
Compare original code
$arg{0}
with fixed code:
$arg[0]
Solution:
Search all files in your xampp/php/pear
folder 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 function error_handler
and make the last param optional.
In my case it was in 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)
with applied fix:
function error_handler($errno, $errmsg, $file, $line, $vars = null)
Note: I found that "bug" has been already reported on the Apache Friends Support Forum 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()
.
This function has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged.
Solution
Search for all occurrences of each(
(use the space to eliminate function 'foreach' in the result set) and review and update it with function foreach
with proper params used in each file.
An example of while
syntax
while (list($i, $arg) = each($args)) {
can be replaced with
foreach ($args as $i => $arg) {
An example of list
syntax
list(,$first) = each($lines);
can be replaced with
foreach($lines as $first){}
There are some other cases used in If - else
statements that can be replaced by emtpy($args)
followed by foreach($args as $opt_arg){}
to build the variable $opt_arg.
An example of If - else
syntax
if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
can be replaced with
if (!strlen($opt_arg) && !empty($args)) {
foreach($args as $opt_arg){}
4) Solved
If you did all the modification of PEAR correctly your XAMPP should be working with PHP 8.x now.
In my case it was PHP 8.2.0 at the time of writing this guide.
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
Upvotes: 9