3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【PHP(laravel)】Undefined property: stdClassのメッセージが出た時

Last updated at Posted at 2020-12-11

PHPのstdClassは簡単に言うと、プロパティやメソッドが無いオブジェクトです。

その特徴を活かして使われることもありますが、
意図せず「Undefined property: stdClass」のメッセージが表示された場合は
定義していないオブジェクトを使っている可能性があります。

.php
//クラス
class Aaa {
 public $word;
}
.php
//オブジェクト
$a = new Aaa;//定義
$a->word = 'こんにちは';
echo $a->word; //出力:こんにちは

//定義していない変数$bを使うと
$b->word = 'こんにちは';
echo $a->word; //出力:Undefined property: stdClass

私の場合はlaravelでの開発中に意図せず出てきたので、
使っている変数を確かめてみると、メッセージが解消できました。

3
2
0

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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?