object can't add new paramenters

Code:

foreach($imageList->items as $ubmodel){
            $program    = ProgramModel::findfirst($ubmodel->pid);
            $topic  = TopicModel::findfirst($ubmodel->tid);
            $ubmodel->program=$program->title;
            $ubmodel->topic=$topic->title;
            print_r($ubmodel->toarray());
            $result[]=$ubmodel;
}

the output result doesn't have 'program' and 'topic' parameters, but I am sure $program->title and $topic->title have content. my php version is :PHP Version 5.5.9-1ubuntu4.5

Someone have same problem like this? and how to fix it?



18.5k
edited Dec '14

What does $ubmodel->program saves: a related program, his title, or what? I'm confused from what I read.

edited Dec '14

The result from findfirst() is a stdClass, if no result then there is no object returned, it doesn't return a populated or empty model class.