Return to Snippet

Revision: 6013
at April 21, 2008 13:13 by stancell


Updated Code
interface Comparable_Equals
{
    public function equals(self $other);
}


class User
implements Comparable_Equals
{
    public function equals(self $other)
    {
        return $this['id'] == $other['id'];
    }
    // other methods
}

$stancell = User::loadByUsername('stancell');
$user = User::loadById(20);

echo $user->equals($stancell) ? 'The same user' : 'Different user';

Revision: 6012
at April 21, 2008 12:42 by stancell


Initial Code
interface Comparable_Equals
{
    public function equals(self $other);
}


class SampleModel
implements Comparable_Equals
{
    public function equals(self $other)
    {
        return $this['id'] == $other['id'];
    }
}

Initial URL

                                

Initial Description
Sample which shoows how to compare objects by content.

Initial Title
Object equality comparison (comparable equals interface)

Initial Tags
object

Initial Language
PHP