Re: [RFC] User-defined object comparison

From: Date: Wed, 27 Jun 2018 15:46:11 +0000
Subject: Re: [RFC] User-defined object comparison
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-102492@lists.php.net to get a copy of this message
On 27 June 2018 at 16:24, Michał Brzuchalski <michal@brzuchalski.com> wrote: > There is also one more thing I can think of. If __equals and __compareTo > methods > don't have any restrictions for $other parameter typehint then I'll be able > to declare > Foo { > public function __compareTo(int $other): int {} > } > and will get some error on > new Foo() == new DateTime('now'); > This can already happen with other magic methods. For instance: class A { public function __set(int $foo, int $bar) {} } $a = new A; $a->test = 42; # TypeError: Argument 1 passed to A::__set() must be of the type int, string given As long as the implementation correctly unwinds the stack when a Throwable is encountered (__toString *can't* cope with this, and bails out the engine), I don't think this is a problem. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#102492) next »