- Note

php8.1 エラー インターフェイスの判定が厳密になった?

Tag:

php8 → php8.1へアップデートした所、下記のようなエラーが起きました。

Fatal error: During inheritance of SessionHandlerInterface: Uncaught ErrorException: Return type of MySQLSessionHandler::open($save_path, $session_id) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in…

セッションデータをMySQLで管理するためSessionHandlerInterfaceを元に独自のクラスMySQLSessionHandlerを作っており、この部分に関するエラーのようです。

エラーの内容としては
SessionHandlerInterfaceを継承して作成されたMySQLSessionHandlerのopenメソッドの戻り値はboolでないとダメ!
ということなのですが、下記のように正しくboolを返すようになっています。

この場合、php7から使用できる「返り値の型指定」を行う必要があるようです。

参考ページ stackoverflow

追加 2022-04-26

エラーを黙認したい場合、#[\ReturnTypeWillChange]アトリビュートを使用すれば良いようです。

参考ページ

 

コメントを残す