消息:Return 类型的 CI_Session_files_driver::open($save_path, $name) 应该兼容

Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with

安装新的 xampp 版本 (php8) 后出现此错误。并克隆我的 codeigniter 项目。

Message: Return type of CI_Session_files_driver::open($save_path, $name)
should either be compatible with SessionHandlerInterface::open(string $path, string $name):
bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

文件名:drivers/Session_files_driver.php

行号:132

对于遇到此错误的任何其他人,我在升级到 PHP 8.1 后也遇到过。我能找到“修复”它的唯一方法是在 openreadwriteclosedestroy 之前添加 #[\ReturnTypeWillChange] gc/system/libraries/Session/drivers/Session_files_driver.php 中发挥作用。例如:

#[\ReturnTypeWillChange]
public function open($save_path, $name)
{
...

我在重新安装 XAMPP 服务器后遇到了这个错误。我通过添加

解决了这个问题

#[\ReturnTypeWillChange]

对于 Session_files_driver.php file 中的所有方法(open, read, write, close, destroy and gc)。该文件可以在项目文件夹 system/libaries/Session/drivers/Session_files_driver.php

中找到
#[\ReturnTypeWillChange]
public function open($save_path, $name)
{
   ...
}

#[\ReturnTypeWillChange]
public function read($session_id)
{
  ...
}

#[\ReturnTypeWillChange]
public function write($session_id, $session_data)
{
  ...
}

#[\ReturnTypeWillChange]
public function close()
{
  ...
}

#[\ReturnTypeWillChange]
public function destroy($session_id)
{
  ...
}

#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
  ...
}