勉強したことのメモ

Webエンジニア / プログラマが勉強したことのメモ

PHP8.4 & CodeIgniter4でDateTimeImmutableエラー

  CodeIgniter PHP

CodeIgniter4.4.4がPHP8.3だと正常に動作していたが、PHP8.4の環境だと「must be compatible with DateTimeImmutable::createFromTimestamp」という致命的エラーが発生した。以下に対応方法をメモ。

 

エラーメッセージ全文

Fatal error: Declaration of CodeIgniter\I18n\TimeTrait::createFromTimestamp(int $timestamp, $timezone = null, ?string $locale = null) must be compatible with DateTimeImmutable::createFromTimestamp(int|float $timestamp): CodeIgniter\Autoloader\Autoloader in /path/to/codeigniter4/system/I18n/TimeTrait.php on line 266

 

対応方法

「/path/to/codeigniter4/system/I18n/TimeTrait.php」の266行目を以下の通り変更する。

# 変更前
public static function createFromTimestamp(int $timestamp, $timezone = null, ?string $locale = null)

# 変更後(第1引数の宣言を追加)
public static function createFromTimestamp(int|float $timestamp, $timezone = null, ?string $locale = null)

 

参考サイト

https://www.gray.me.uk/codeigniter/codeigniter-4-fresh-install-timetrait-error

 - CodeIgniter PHP

  関連記事

CodeIgniterのバージョンの調べ方
CodeIgniterのバージョンの調べ方

CodeIgniterを使っているシステムがあったが、どうも記憶しているディレク ...

CodeIgniter4 & jQueryを用いて同一サイト内でajax通信する方法
CodeIgniter4 & jQueryを用いて同一サイト内でajax通信する方法

CodeIgniter4.4.4 & jQueryを用いて同一サイト内で ...

CodeIgniter4 & reCAPTCHA でお問い合わせフォームを作成する方法
CodeIgniter4 & reCAPTCHA でお問い合わせフォームを作成する方法

以前CodeIgniter4.4.4で簡易的なお問い合わせページを作成したが、今 ...

CodeIgniter3でCronを実行する方法
CodeIgniter3でCronを実行する方法

CodeIgniter3系で特定の処理をCronで自動実行したかった。以下に設定 ...

CodeIgniter4でのメール送信方法(テキスト・HTMLメール)
CodeIgniter4でのメール送信方法(テキスト・HTMLメール)

CodeIgniter4.4.4でテキストメール及びHTMLメールを送信したい。 ...