I have a code User::find(0) that will find and return data of first user in database type object. I can set the value like $user->name = "Name 1" or $user->name = "Name 2".
"Cannot use object of type stdClass as array"
I made a new variable like $teacher = (object) [] and $teacher = new \stdClass. I can set the value like $teacher->name = "Teacher 1". But, I will get above error if I set it like $teacher['name'] = "Teacher 1".
Expected type "object". Found string[].
So, I tried to make $teacher = array() and $teacher = []; I can set the value like $teacher['name'] = "Teacher 1", but I will get above error if I set it with $teacher->name = "Teacher 2".
So, I'm confused why User::find(0) object can be set using '->' and '[]'. I'm still learning to use documentation. I spent alot of time but still can't find it even in another website. Can you you tell me how can I make the same object like User::find(0) that I can set the value using '->' and '[]'?