ThinkPHP安装、运行报错问题解决过程

事件背景

在电脑环境相当混乱之后作者选择了重新装系统,顺便把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!

posted @ 2022-02-14 19:14  limonene0x  阅读(5422)  评论(0编辑  收藏  举报