<?php
trait Eq
{
abstract public function equiv(Eq $lhs, Eq $rhs): bool;
}
class Tuple2
{
use Eq;
public function __construct(public Eq $key, public Eq $value) {}
public function equiv(Eq $lhs, Eq $rhs): bool
{
return $lhs->key->equiv($lhs->key, $rhs->key) && $lhs->value->equiv($lhs->value, $rhs->value);
}
}
class Tuple3
{
use Eq;
public function __construct(public Eq $key, public Eq $value, public Eq $column) {}
public function equiv(Eq $lhs, Eq $rhs): bool
{
return $lhs->key->equiv($lhs->key, $rhs->key)
&& $lhs->value->equiv($lhs->value, $rhs->value)
&& $lhs->column->equiv($lhs->column, $rhs->column);
}
}
function check_equiv(Eq $lhs, Eq $rhs)
{
return $lhs->equiv($lhs, $rhs);
}
var_dump(check_equiv(
new Tuple3(new Tuple2(1, 2), new Tuple2(3, 4), new Tuple2(5, 6)),
new Tuple3(new Tuple2(1, 2), new Tuple2(3, 4), new Tuple2(5, 6))
));
Fatal error: Uncaught TypeError: Tuple2::__construct(): Argument #1 ($key) must be of type Eq, int given, called in /in/Hdmot on line 35 and defined in /in/Hdmot:10
Stack trace:
#0 /in/Hdmot(35): Tuple2->__construct(1, 2)
#1 {main}
thrown in /in/Hdmot on line 10
Process exited with code 255.