CActiveRecordBehavior owner and event->sender

Hi there. Have you any ideas when CActiveRecordBehavior->owner and $event->sender (for example CActiveRecordBehavior::beforeSave($event)) could be different objects?

Code example:


class SomeBehavior extends CActiveRecordBehavior


    public function beforeSave($event)


        var_dump($this->owner === $event->sender); // echoes false




I’d be surprised if they’d be different objects. But what happens if you do:

var_dump($this->owner == $event->sender);

(use == instead of ===). Does it still return false?

Yes. It still returns false. And there is no difference == or === because if it is pointers to one object such expression should returns true. Seems like yii creates copy of object… or something like that.

Sorry. My fault. There was something like:

$a = new ArObj();

$b = clone $a;


so, sender was $b but owner $a. =)

Have you tried doing a var_dump($this->owner) and var_dump($event->sender)? Maybe that output shows something that’ll explain things.