avinashizhere
avinashizhere

Reputation: 455

Cannot use object of type stdClass as array

Here is what i'm doing and i'm getting this error

echo empty($record['name']) ? $previous_data['w_name'] : $record['name'];

what might be the problem? Reason why i'm trying to do is, i'm using this logic to update user's profile, if he doesn't want to update he can leave that field blank, and i've this previous_data array with his old information stored, if user leaves the field blank i'm going to store that previous value in it from previous data array but if user does change/update the field i'll store new value in it.

$new_data = array( 'name' => empty($record['name']) ? $previous_data['w_name'] : $record['name'] );

Upvotes: 1

Views: 466

Answers (1)

Thornuko
Thornuko

Reputation: 287

Instead of accessing the properties by using $record['name'] try using $record->name.

As the error says, you are trying to treat an object as an array.

Upvotes: 3

Related Questions