In codeigniter, I retrieve database results and store it in a variable like the following:
$data['user'] = $this->some_model->get_by_id($id);
Say the above retrieves only the user_id and the user_name, so the variables will be
$data['user']->user_id;
$data['user']->user_name;
Now, say, I want to assign another value (eg. age), can I do the following?
$data['user']->age = '23';
Technically, yes, you can. But it’s bad practice. Assigning values to undeclared object properties is “expensive” in PHP. Plus it is not always clear to the reader where a value came from so this make code maintenance more difficult.