There is a foreach loop that iterates attributes. If an object has the next attribute, the code assigns a value for this attribute:
foreach ($record as $attribute=>$value) {
    if ($object->has_attribute($attribute)) {
        $object->$attribute = $value;
    }
}
I don't understand why we have to use $object->$attribute instead of $object->attribute?  The latter seems more logical to me because it looks like basic OOP, but in this case the script doesn't work.
I just want to know why. Please give me some insights.
 
     
    