<?php
trait Comparable
{
abstract public function isGreaterThan($other);
public function isLesserThan($other)
{
return $other->isGreaterThan($this);
}
public function equals($other)
{
return !($this->isGreaterThan($other) || $this->isLesserThan($other));
}
}
class SimpleInt
{
use Comparable;
private $value;
public function __construct($value)
{
$this->value = $value;
}
public function isGreaterThan($other)
{
return $this->value > $other->value;
}
}
$i = new SimpleInt(10);
echo (int)($i->equals($i));