LoginSignup
1
0

More than 5 years have passed since last update.

繰り返し処理内での「Fatal error: Cannot redeclare」

Posted at

繰り返し処理内で関数を定義したら繰り返しの2回目以降の処理で
以下のエラーが発生

Fatal error: Cannot redeclare

調べてみると同じ名前の関数は定義できないよ!というエラーらしい。
繰り返し処理の1回目で呼び出した関数が、2回目以降の呼び出し時に
定義済みとされているみたい。

ググってみて以下の記事を参考に修正しました。
「Fatal error: Cannot redeclare」と表示されるとき

function_exist関数で関数が定義済みかを判定した後に
未定義の場合のみ関数を定義するという処理です。

なんか個人的にはイマイチしっくり来てないので
もし、もっとスマートな解決方法をご存知の方がいたら教えてください。

とりあえず、先人の知恵に感謝!

1
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0