事件背景
在電腦環境相當混亂之后作者選擇了重新裝系統,順便把PHP更新到了最新版本,打算開始重新寫沒怎么開始的畢業設計,我的畢業設計是ThinkPHP框架下的一個網站系統。
眾所周知,ThinkPHP6要求使用Composer來創建項目,拉取源碼,顧我先將PHP解壓,然后安裝了Composer,到此處一切順利,正當我覺得萬事大吉,創建項目即可的時候,問題出現了……
問題出現
我使用了非常標准的一行命令來創建項目composer create-project topthink/think tp
然后就開始出現了一長條的報錯
> @php think service:discover PHP Fatal error: During inheritance of ArrayAccess: Uncaught think\exception\ErrorException: Return type of think\Request::offsetGet($name) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Request.php:2156 Stack trace: #0 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Request.php(23): think\initializer\Error->appError() #1 C:\Users\[username]\Desktop\tp\vendor\composer\ClassLoader.php(571): include('...') #2 C:\Users\[username]\Desktop\tp\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile() #3 C:\Users\[username]\Desktop\tp\app\Request.php(5): Composer\Autoload\ClassLoader->loadClass() #4 C:\Users\[username]\Desktop\tp\vendor\composer\ClassLoader.php(571): include('...') #5 C:\Users\[username]\Desktop\tp\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile() #6 [internal function]: Composer\Autoload\ClassLoader->loadClass() #7 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(375): ReflectionClass->__construct() #8 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(251): think\Container->invokeClass() #9 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Console.php(156): think\Container->make() #10 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Console.php(112): think\Console->makeRequest() #11 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Console.php(94): think\Console->initialize() #12 [internal function]: think\Console->__construct() #13 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(394): ReflectionClass->newInstanceArgs() #14 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(251): think\Container->invokeClass() #15 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(130): think\Container->make() #16 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(510): think\Container->get() #17 C:\Users\[username]\Desktop\tp\think(10): think\Container->__get() #18 {main} in C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Request.php on line 23 [think\exception\ErrorException] During inheritance of ArrayAccess: Uncaught think\exception\ErrorException: Return type of think\Request::offsetGet ($name) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChan ge] attribute should be used to temporarily suppress the notice in C:\Users\[username]\Desktop\tp\vendor\topthink\fra mework\src\think\Request.php:2156 Stack trace: #0 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Request.php(23): think\initializer\Error->appEr ror() #1 C:\Users\[username]\Desktop\tp\vendor\composer\ClassLoader.php(571): include('...') #2 C:\Users\[username]\Desktop\tp\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile() #3 C:\Users\[username]\Desktop\tp\app\Request.php(5): Composer\Autoload\ClassLoader->loadClass() #4 C:\Users\[username]\Desktop\tp\vendor\composer\ClassLoader.php(571): include('...') #5 C:\Users\[username]\Desktop\tp\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile() #6 [internal function]: Composer\Autoload\ClassLoader->loadClass() #7 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(375): ReflectionClass->__construc t() #8 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(251): think\Container->invokeClas s() #9 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Console.php(156): think\Container->make() #10 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Console.php(112): think\Console->makeRequest() #11 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Console.php(94): think\Console->initialize() #12 [internal function]: think\Console->__construct() #13 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(394): ReflectionClass->newInstan ceArgs() #14 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(251): think\Container->invokeCla ss() #15 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(130): think\Container->make() #16 C:\Users\[username]\Desktop\tp\vendor\topthink\framework\src\think\Container.php(510): think\Container->get() #17 C:\Users\[username]\Desktop\tp\think(10): think\Container->__get() #18 {main} Script @php think service:discover handling the post-autoload-dump event returned with error code 255
尤其是當最后一行代碼以紅色的樣子出現在我面前的時候,我爆炸了!
【省流小助手:要看解決方法,直接拉到結尾】
開始嘗試解決
一開始,我以為問題來自於我的Composer沒有安裝正確,所以我嘗試了把Composer卸載,然后重新安裝,這個時候發現在第一次安裝的時候,因為一些你懂得的原因,我勾選了使用代理,然后無法取消勾選,但我也沒當回事,繼續了安裝,但是裝好之后再次嘗試……
依舊是Script @php think service:discover handling the post-autoload-dump event returned with error code 255
我又認為我原來用的是Composer1,現在是Composer2,是不是這個原因導致的?結果當我一番折騰退回到Composer1之后,依 舊 不 行 !
這個時候我是無語的,我開始懷疑是不是網絡環境的問題,當我把代理關掉,文件夾都不會創建就會開始報錯告訴我連接不到我的代理服務器,無奈我又重新打開了代理,但是問題沒有解決啊!我繼續探索,既然懷疑問題來自於代理,那我就把代理關了?
經過漫長的尋找,我終於在環境變量的User中發現了一條:http_proxy
,呼~我松了一口氣,把它刪掉之后我又卸載了Composer,果然,在重新安裝的時候我有機會選擇不使用代理了(最終也還是會顯示要求忽略注冊表,重新設置代理,並沒有恢復到最原始的狀態……求解答)
然而!然而!當我以不連接代理的狀態再次在Composer中輸入那行熟悉的代碼composer create-project topthink/think tp
這個世界戛然而止……報錯沒有任何改變!依舊是Script @php think service:discover handling the post-autoload-dump event returned with error code 255
俗話說得好,當上帝給你關上一扇門,必然不會直接把窗戶給你打開……
雖然我的畢業設計沒做多少,但是在重新裝系統前怎么說也是做了一部分的,原來的項目代碼我還留着,於是我把原來的項目代碼解壓,打開PHPstorm,配置好開始運行,結果!不能訪問!出現了HTTP 500……
嗯》?原來好好的能用的怎么也不能用了?
我抓狂了,在電腦前愣了一會之后,我決定,,, 毀 滅 吧 ! 老子不做了……
可是當我在床上思考了半小時人生之后,我重新坐回到了電腦前,面對着這個在網絡上搜索了好幾頁結果也找不到答案的問題,我開始自行探索……是不是我的新系統環境有什么問題了?
於是我裝了一台虛擬機……把PHP和Composer都放進去,整個系統只有這兩個軟件……我倒要看看全新的電腦是什么情況……
果不其然……在只有這兩個軟件的情況下,報錯依舊是Script @php think service:discover handling the post-autoload-dump event returned with error code 255
,而我此時已經幾乎排除了Composer的問題,那也就是說,問題可能在於PHP?我想起了我作死地想在新電腦上用新版本的PHP這件事,就想着……要不然?我換個舊版本試試?於是我去PHP官網重新下載了一個舊版本的PHP……放進虛擬機,重新安裝Composer……輸入那行我輸入了無數次的命令……
composer create-project topthink/think tp
欣喜若狂啊兄弟們!成了!
困擾了我整整大半天(?)的問題……解決了!原來是PHP版本的問題……
啊!這一刻我的內心是無語的……我被一個PHP版本折騰了大半天,關鍵是整個網上搜不到任何此類錯誤……唉,算了吧,是我太奇葩,我知錯。。。
感悟
經歷了這一切,我的思想得到了升華,我的忍耐力得到了鍛煉,這個報錯磨礪了我的意志,提升了我自我解決問題的能力,深刻反思(被迫復習)了控制變量法的使用,……(此處省略兩千字)
報錯結論
所以關於Script @php think service:discover handling the post-autoload-dump event returned with error code 255
報錯的結論就是……它可能是因為你的PHP版本太高了導致的……換個低點的PHP版本試試吧!祝你成功~ <_<
關於此條報錯可能存在其他能搜到的錯誤原因,本文僅記錄作者遇到的此次問題的解決方法以及心路歷程,如能產生幫助,那我十分榮幸。
祝大家配置環境順順利利,沒有報錯!0 Error, 0 Warning!