Provides
Equatablefor PHP 7+ (inspired by Java).
composer require litgroup/equatable:^2.0
interface Equatable
{
/** * Checks if this object is equal to another one. */publicfunctionequals(Equatable$another): bool;
}namespaceAcme;
useLitGroup\Equatable\Equatable;
class User
{
private$username;
private$email;
publicfunction__construct(string$username, string$email)
{
$this->username = $username;
$this->email = $email;
}
publicfunctiongetUsername(): string
{
return$this->username;
}
publicfunctiongetEmail(): string
{
return$this->email;
}
/** * Example of implementation of Equatable::equals() */publicfunctionequals(Equatable$another): bool
{
return$anotherinstanceOf User &&
$another->getUsername() == $this->getUsername() &&
$another->getEmail() == $this->getEmail()
;
}
}See LICENSE file.