2.

Cannot use object of type stdClass as array エラーの対処

編集
この記事の要点
  • PHP の Cannot use object of type stdClass as array
  • 原因: stdClass オブジェクトを $obj['key'] のように配列風アクセスしている
  • 対処: $obj->key(アロー記法)でプロパティアクセス
  • 配列で扱いたいなら (array)$obj または json_decode($json, true)(連想配列モード)

 

エラー内容

Fatal error: Uncaught Error: Cannot use object of type stdClass as array in ...

 

対処法

配列としてstdClassオブジェクトを扱ってしまったら出るエラーです。

$配列[インデックス]という扱いではなく、$stdClass->インデックスという扱いにすれば解決できます。

編集
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