Search code examples
phpsessioncodeigniter-3

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


I got this error after install a new xampp version (php8). and clone my codeigniter project.

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

Filename: drivers/Session_files_driver.php

Line Number: 132


Solution

  • For anyone else that comes across this error, I also experienced it after upgrading to PHP 8.1. The only way I could find to "fix" it was by adding #[\ReturnTypeWillChange] before the open, read, write, close, destroy and gc functions in /system/libraries/Session/drivers/Session_files_driver.php. For example:

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