litgroup / equatable
Provides EquatableInterface for PHP 7+
Installs: 374
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/litgroup/equatable
Requires
- php: ^7.0
This package is auto-updated.
Last update: 2023-11-12 22:37:49 UTC
README
Provides
Equatable
for PHP 7+ (inspired by Java).
Installation
composer require litgroup/equatable:^2.0
What is inside
interface Equatable { /** * Checks if this object is equal to another one. */ public function equals(Equatable $another): bool; }
Example of usage
namespace Acme; use LitGroup\Equatable\Equatable; class User { private $username; private $email; public function __construct(string $username, string $email) { $this->username = $username; $this->email = $email; } public function getUsername(): string { return $this->username; } public function getEmail(): string { return $this->email; } /** * Example of implementation of Equatable::equals() */ public function equals(Equatable $another): bool { return $another instanceOf User && $another->getUsername() == $this->getUsername() && $another->getEmail() == $this->getEmail() ; } }
LICENSE
See LICENSE file.