sobatcoding.com - Tutorial cara mengatasi Error Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with di Codeigniter 3
Apakah kalian pernah mengalami pesan error ketika memakai codeigniter 3 di PHP versi 8.1 * ke atas seperti berikut
A PHP Error was encountered
Severity: 8192
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
Admin akan share pengalaman admin saat mengalami kendala tersebut dan cara mengatasinya.
Tutorial ini admin dapat dari stackoverflow dimana cara mengatasinya sangat mudah, yaitu kalian tinggal tambahkan variable #[\ReturnTypeWillChange] di file system\libraries\Session\drivers\Session_files_driver.php. Tambahkan variable tersebut di beberapa fungsi seperti open, read, write, close, destroy and gc. Letakkan variable #[\ReturnTypeWillChange] sebelum fungsi tersebut di definisikan.
Contoh seperti berikut
#[\ReturnTypeWillChange]
public function open($save_path, $name)
{
if ( ! is_dir($save_path))
{
if ( ! mkdir($save_path, 0700, TRUE))
{
throw new Exception("Session: Configured save path '".$this->_config['save_path']."' is not a directory, doesn't exist or cannot be created.");
}
}
.....
Selamat mencoba.
Sekian tutorial kali ini. Semoga bermanfaat.
Jika teman-teman memiliki pertanyaan atau saran mengenai artikel ini, jangan ragu untuk meninggalkan komentar pada form di bawah
Komentar 0