當(dāng)我按照官方[手冊(cè)][1]中有關(guān)如何安裝 PEAR 的說(shuō)明進(jìn)行操作時(shí),出現(xiàn)了此錯(cuò)誤:
致命錯(cuò)誤:未捕獲錯(cuò)誤:無(wú)法在 C:xampp_latestphp 中打開(kāi)所需的 'phar://go-pear.phar/index.php' (include_path='C:xampp_latestphpPEAR') go-pear.phar:1284 堆棧跟蹤:#0 {main} 拋出在 C:xampp_latestphpgo-pear.phar 第 1284
行
我嘗試尋找其他解決方案并找到了[這個(gè)][2]。但是,我仍然無(wú)法安裝 pear,并且仍然收到此錯(cuò)誤:
PHP 致命錯(cuò)誤:C:xampp_latestphpgo-pear.php 第 1182
行不再支持帶大括號(hào)的數(shù)組和字符串偏移訪問(wèn)語(yǔ)法。
我嘗試通過(guò)基于網(wǎng)絡(luò)和命令行的安裝,但得到了同樣的錯(cuò)誤。
又是一個(gè)更新.. 我繼續(xù)進(jìn)行更多搜索并得到了這個(gè): 關(guān)聯(lián) 因此,我嘗試按照錯(cuò)誤中的建議將不同文件中的大括號(hào)更改為方括號(hào),最后,我收到此錯(cuò)誤:
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/
基本上,xampp 提供的 PEAR 并未更新為在 PHP 8.x 下運(yùn)行。并面臨 PHP 8.0 中多個(gè)已棄用和刪除的功能,這些功能會(huì)導(dǎo)致 PHP 致命錯(cuò)誤。
1) 訪問(wèn)字符問(wèn)題
第一個(gè)問(wèn)題是 字符串訪問(wèn)使用大括號(hào) {}
訪問(wèn)時(shí)從零開(kāi)始的偏移量已被刪除,只能使用方括號(hào) []
。
比較原始代碼
$arg{0}
使用固定代碼:
$arg[0]
解決方案:
使用正則表達(dá)式 \{(\$[a-zA-Z0-9\+]*)\}
搜索 xampp/php/pear
文件夾中的所有文件并替換與 [$1]
重要:檢查每次出現(xiàn)的情況,不要更改腳本中的正則表達(dá)式!?。?
2)未捕獲的ArgumentCountError問(wèn)題
第二個(gè)問(wèn)題是 php 函數(shù) set_error_handler 哪里是 刪除了 PHP 8.0.0 中的最后一個(gè)參數(shù)。
回調(diào)函數(shù)需要五個(gè)參數(shù),但它只獲得四個(gè)參數(shù),因此調(diào)用失敗,并顯示 PHP Fatal error: Uncaught ArgumentCountError: Too Fewarguments to function error_handler( ),4 項(xiàng)通過(guò),正好 5 項(xiàng)預(yù)期
。
解決方案:
搜索 set_error_handler(
調(diào)用并找到引用的回調(diào)函數(shù) error_handler
并將最后一個(gè)參數(shù)設(shè)為可選。
就我而言,它位于腳本 xampp\php\pear\pearcmd.php
中,函數(shù)定義位于第 446 行:
比較原始函數(shù)定義:
function error_handler($errno, $errmsg, $file, $line, $vars)
應(yīng)用修復(fù)后:
function error_handler($errno, $errmsg, $file, $line, $vars = null)
注意:我發(fā)現(xiàn) Apache 上已經(jīng)報(bào)告了“bug”好友支持論壇已于 2021 年 9 月回歸。
3)未定義函數(shù)each()問(wèn)題
第三個(gè)問(wèn)題是刪除了 PHP 函數(shù) each() ,即拋出PHP致命錯(cuò)誤:未捕獲錯(cuò)誤:調(diào)用未定義的函數(shù)each()
。
解決方案
搜索所有出現(xiàn)的 every(
(使用空格消除結(jié)果集中的函數(shù)“foreach”),并使用函數(shù) foreach
進(jìn)行檢查和更新,并在每個(gè)中使用正確的參數(shù)文件。\
while
語(yǔ)法示例
while (list($i, $arg) = each($args)) {
可以替換為
foreach ($args as $i => $arg) {
list
語(yǔ)法示例
list(,$first) = each($lines);
可以替換為
foreach($lines as $first){}
還有一些在 If - else
語(yǔ)句中使用的其他情況,可以用 emtpy($args)
后跟 foreach($args as $opt_arg ){}
構(gòu)建變量 $opt_arg。
If - else
語(yǔ)法示例
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
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)