Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

Equatable for PHP

Provides Equatable for PHP 7+ (inspired by Java).

VersionDownloadsLicense

Installation

composer require litgroup/equatable:^2.0

What is inside

interface Equatable
{
/** * Checks if this object is equal to another one. */publicfunctionequals(Equatable$another): bool;
}

Example of usage

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()
;
}
}

LICENSE

See LICENSE file.

About

Provides Equatable interface for PHP 7+

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages