Re: Custom object equality

From: Date: Wed, 18 Oct 2023 13:03:06 +0000
Subject: Re: Custom object equality
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-121389@lists.php.net to get a copy of this message
Le 18/10/2023 à 14:50, someniatko a écrit :
Hi internals, This approach allows combining - no BC break - ~= is a new syntax which is unavailable in older PHP versions - explicitly showing an intent that objects are compared using a custom comparison, rather than standard PHP one - allow to skip writing boilerplate equals() methods which just forward equals() to the nested objects - standardize such comparisons on the language level Of course how exactly this operator looks may be changed, ~= is just an example. WDYT?
I'm not fond of operator overloading, I actually quite hate it, I like the expressiveness of an equals() method. I would very much prefer to have a set of standard interfaces such as Comparable { compareTo($other): int } or Equatable { equals($other): bool; } which the standard API and userland libraries could make use of. In all cases, I don't like the ~= choice because in my mind it literally translates to "is approximately/barely/maybe comparable to". By the way, please  do not use abbreviations such as WDYT, I'm not a native english speaker and I don't know all abbreviations, I had to duckduckgo' it. Regards, -- Pierre

« previous php.internals (#121389) next »