https://github.com/hdimo/php-equtable
interface for php object comparaison
https://github.com/hdimo/php-equtable
equatable php
Last synced: 4 days ago
JSON representation
interface for php object comparaison
- Host: GitHub
- URL: https://github.com/hdimo/php-equtable
- Owner: hdimo
- License: mit
- Created: 2022-01-31T23:26:52.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-06T21:18:51.000Z (over 4 years ago)
- Last Synced: 2025-12-14T11:20:37.889Z (6 months ago)
- Topics: equatable, php
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/hdimo/php-equtable/actions/workflows/php.yml)
An equatable interface for object comparison in PHP.
when we want to compare objects in php with == yields incorrect results even if they are equal in all properties.
this library provides an interface to compare two objects by returning their properties and checks if they are equal.
Installation
```shell script
composer require jkhaled/equatable
```
usage example :
```php
require_once __DIR__ . '/vendor/autoload.php';
class User extends \Jkhaled\Equatable\AbstractEquatable
{
private $id;
private $firstname;
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
return $this;
}
public function getFirstname()
{
return $this->firstname;
}
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
// the properties to be compared to check equality
public function getProperties(): array
{
return ['id', 'firstname'];
}
}
$user1 = (new User())
->setFirstname('khaled')
->setId(111);
$user2 = (new User())
->setFirstname('khaled')
->setId(111);
var_dump($user1 === $user2); // false
var_dump($user1->equalTo($user2)); // true
```