6.

エラー一覧

編集

PHPのエラー一覧に関する記事です。実行時に発生する代表的なエラー・警告と、それらへの対応をまとめています。

子ページからエラーを選択してください。

PHPのエラー種別

種類意味挙動
Fatal error致命的エラースクリプト停止
Parse error構文エラースクリプト停止(実行前)
Warning警告続行するが想定外動作の可能性
Notice軽微な通知続行。未定義変数参照など
Uncaught Error / Exception未捕捉の例外スクリプト停止

子ページのカテゴリ

実行時間・メモリ

  • Maximum execution time of 30 seconds exceeded — max_execution_time の調整、長時間処理の分割

型・変換エラー

  • Cannot use object of type stdClass as array — オブジェクトを配列としてアクセス
  • Object of class stdClass could not be converted to string — 暗黙の文字列変換
  • A non well formed numeric value encountered — 数値変換できない文字列の演算

未定義参照

  • Use of undefined constant — 定数の未定義(クォート漏れが多い)
  • Class 'Xxx' not found — autoload設定や名前空間の問題
  • Call to undefined method — メソッド名のtypoやライブラリのバージョン違い

環境・拡張モジュール

  • requested PHP extension mbstring/dom is missing — php-mbstring 等の追加インストール
  • could not find driver — PDOドライバが未インストール
  • Your requirements could not be resolved — composerの依存解決失敗、PHP拡張バージョンの不一致

ヘッダ・I/O

  • Cannot modify header information - headers already sent — 出力後に header()/setcookie() を呼んだ
  • XMLWriter::openUri(): Unable to resolve file path — パス指定の誤り

ネットワーク

  • getaddrinfo failed: Name or service not known — 名前解決失敗

共通する基本の確認

  1. エラーの発生ファイル名と行番号を確認
  2. そのファイルを開き、該当行の変数の中身var_dump()dd() で確認
  3. 本番でエラーが画面に出ている場合は display_errors=Off にし、error_log でログに送る
  4. PHPバージョンによって挙動が変わるエラーが多いので、php -v で現行バージョンを確認

関連

  • PHP本体の操作・設定は親ページ「PHP」を参照
  • composer絡みのエラーは「Your requirements could not be resolved」ページが入口
編集
Post Share
子ページ
  1. Fatal error: Maximum execution time of 30 seconds exceeded in...
  2. Fatal error: Uncaught Error: Cannot use object of type stdClass as array in ...
  3. Warning: Use of undefined constant ... - assumed '...' (this will throw an Error)
  4. ERROR: Call to undefined method Maatwebsite\Excel\Excel::load()
  5. Maximum execution time of 30 seconds exceeded
  6. Your requirements could not be resolved to an installable set of packages. ... To enable extensions, verify that they are enabled in your .ini files:
  7. could not find driver
  8. the requested PHP extension mbstring is missing from your system.
  9. the requested PHP extension dom is missing from your system.
  10. A non well formed numeric value encountered
  11. Warning: Cannot modify header information - headers already sent by ...
  12. php_network_getaddresses: getaddrinfo failed: Name or service not known
  13. XMLWriter::openUri(): Unable to resolve file path
  14. Object of class stdClass could not be converted to string
  15. Class 'Google_Service_Youtube' not found
同階層のページ
  1. インストール方法
  2. 文法
  3. Composerのインストール
  4. 内部関数
  5. フレームワーク
  6. エラー一覧
  7. 改行出力
  8. printとechoの違い
  9. シングルクォートとダブルクォートの違い
  10. returnとyieldの違い
  11. var_dumpをログ出力
  12. CSV読み込み
  13. 待機・処理の遅延
  14. ログファイルにエラーを出力する方法
  15. エラーログ出力関数
  16. URLパラメータの配列化
  17. empty, is_null. issetの判定比較表
  18. httpステータスコードの付与
  19. バージョンの確認
  20. php.ini
  21. APIを呼び出す方法
  22. 外部ファイルを呼び出す方法
  23. カンマ区切りの文字列を配列に変換
  24. 配列からランダムに値を取り出す方法
  25. Webスクレイピング