Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- interface Comparable {
- function compareTo($other): int;
- }
- class BigInteger implements Comparable {
- public function __construct(private int $value) {}
- public function compareTo($other): int {
- $type = gettype($other);
- switch ($type) {
- case integer::class:
- return $this->compareToInt($other);
- default:
- throw new \LogicException('Cannot compare \''.BigInteger::class.'\' with \''.$type.'\'');
- }
- }
- protected function compareToInt(int $other): int {
- return $this->value - $other;
- }
- }
- $a = new BigInteger(15);
- var_dump($a->compareTo(35));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement