Compare two Doctrine_Record objects

为君一笑 提交于 2019-12-23 22:27:56

问题


How do I compare two Doctrine_Record objects to see if they are "equal"?

On the domain login I am considering, two objects are equal if they have the same properties values, except the id and the created_at and updated_at fields (a la Timestampable).


回答1:


First idea which comes into my mind is:

class User extends Doctrine_Record
{
  public function equals(User $user)
  {
    $left = $this->toArray();
    $right = $user->toArray();

    unset($left['id'], $left['created_at'], $left['updated_at']);
    unset($right['id'], $right['created_at'], $right['updated_at']);

    return $left == $right;
  }
}


来源:https://stackoverflow.com/questions/3874524/compare-two-doctrine-record-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!