Yii Framework Forum: CActiveRecordBehavior owner and event->sender - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CActiveRecordBehavior owner and event->sender Rate Topic: -----

#1 User is offline   UX.InfoGate 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 10-February 10

Posted 25 April 2010 - 02:36 PM

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

Code example:
<?php

class SomeBehavior extends CActiveRecordBehavior
{
    public function beforeSave($event)
    {
        var_dump($this->owner === $event->sender); // echoes false
    }
}


Thanks!
0

#2 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 26 April 2010 - 06:06 PM

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?
0

#3 User is offline   UX.InfoGate 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 10-February 10

Posted 26 April 2010 - 06:26 PM

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.
0

#4 User is offline   UX.InfoGate 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 10-February 10

Posted 26 April 2010 - 06:40 PM

Sorry. My fault. There was something like:
$a = new ArObj();
$b = clone $a;
...
$b->save();

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

#5 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 26 April 2010 - 06:43 PM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users