Let\'s say I have an object - a User object in this case - and I\'d like to be able to track changes to with a separate class. The User object should not have to change it\'s be
There is a whole site on php.net only dealing with comparing objects:
http://php.net/manual/en/language.oop5.object-comparison.php
Also a good read:
http://www.tuxradar.com/practicalphp/6/12/0
I would say you should use the "clone" method when copying your object and then later compare as said in the php.net article.
Also a fast way would be by declaring a static method in the class that just compares the relevant "properties" like lets say "username", "password", "cookie",...
class User
{
public $username;
public $password;
public $cookie;
# other code
public static function compare(&$obj1, &$obj2)
{
if ($obj1->username != $obj2->username)
return 0
if ($obj1->password != $obj2->password)
return 0
if ($obj1->cookie != $obj2->cookie)
return 0
return 1
}
};