PHP code example of litgroup / equatable

1. Go to this page and download the library: Download litgroup/equatable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

litgroup / equatable example snippets


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

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