On Tue, 3 Mar 2020 at 14:45, Terje Slettebø <
terje.slett...@sandefjordbredband.net> wrote:

>
> I agree that this makes sense. However, as someone else pointed out, one
> problem with interfaces is that they constrain the types that may be used.
>


An interface doesn't have to define types, and in this case it wouldn't
make sense for it to do so.

Without generics, the only option would be to constrain everything to
"static", but as you say, that rules out a lot of use cases.

So the interfaces would simply require that the functions exist, and not
say anything about their types. This is already the case with other
built-in interfaces; for instance, Iterator places no constraint on the
return of the current() and key() functions:

# https://3v4l.org/U0gKD
class Foo implements Iterator
{
    public function current(): Foo { return $this; }
    public function key(): Foo { return $this; }
    public function next(): void {}
    public function rewind(): void {}
    public function valid(): bool { return true; }
}

Similarly, the interface can't guarantee that the implementation does
anything useful, or even runs without error. All it does is force the user
to at least consider

Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to