Windows XAMPP PHP 8.1.10 中的 Pear 安装
P粉141911244
P粉141911244 2023-12-31 10:46:35
0
1
353

当我按照官方[手册][1]中有关如何安装 PEAR 的说明进行操作时,出现了此错误:

致命错误:未捕获错误:无法在 C:xampp_latestphp 中打开所需的 'phar://go-pear.phar/index.php' (include_path='C:xampp_latestphpPEAR') go-pear.phar:1284 堆栈跟踪:#0 {main} 抛出在 C:xampp_latestphpgo-pear.phar 第 1284

我尝试寻找其他解决方案并找到了[这个][2]。但是,我仍然无法安装 pear,并且仍然收到此错误:

PHP 致命错误:C:xampp_latestphpgo-pear.php 第 1182 行不再支持带大括号的数组和字符串偏移访问语法。

我尝试通过基于网络和命令行的安装,但得到了同样的错误。

又是一个更新.. 我继续进行更多搜索并得到了这个: 关联 因此,我尝试按照错误中的建议将不同文件中的大括号更改为方括号,最后,我收到此错误:

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粉141911244
P粉141911244

全部回复(1)
P粉222320176

基本上,xampp 提供的 PEAR 并未更新为在 PHP 8.x 下运行。并面临 PHP 8.0 中多个已弃用和删除的功能,这些功能会导致 PHP 致命错误。

1) 访问字符问题
第一个问题是 字符串访问使用大括号 {} 访问时从零开始的偏移量已被删除,只能使用方括号 []

比较原始代码

$arg{0}

使用固定代码:

$arg[0]

解决方案:
使用正则表达式 \{(\$[a-zA-Z0-9\+]*)\} 搜索 xampp/php/pear 文件夹中的所有文件并替换与 [$1]
重要:检查每次出现的情况,不要更改脚本中的正则表达式!!!


2)未捕获的ArgumentCountError问题
第二个问题是 php 函数 set_error_handler 哪里是 删除了 PHP 8.0.0 中的最后一个参数
回调函数需要五个参数,但它只获得四个参数,因此调用失败,并显示 PHP Fatal error: Uncaught ArgumentCountError: Too Fewarguments to function error_handler( ),4 项通过,正好 5 项预期

解决方案:
搜索 set_error_handler( 调用并找到引用的回调函数 error_handler 并将最后一个参数设为可选。
就我而言,它位于脚本 xampp\php\pear\pearcmd.php 中,函数定义位于第 446 行:

比较原始函数定义:

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

应用修复后:

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

注意:我发现 Apache 上已经报告了“bug”好友支持论坛已于 2021 年 9 月回归。


3)未定义函数each()问题
第三个问题是删除了 PHP 函数 each() ,即抛出PHP致命错误:未捕获错误:调用未定义的函数each()

解决方案
搜索所有出现的 every( (使用空格消除结果集中的函数“foreach”),并使用函数 foreach 进行检查和更新,并在每个中使用正确的参数文件。\

while 语法示例

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

可以替换为

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

list 语法示例

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

可以替换为

foreach($lines as $first){}

还有一些在 If - else 语句中使用的其他情况,可以用 emtpy($args) 后跟 foreach($args as $opt_arg ){} 构建变量 $opt_arg。

If - else 语法示例

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

可以替换为

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

PEAR 终于可以使用 XAMPP 版本: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
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!