Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102546 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65949 invoked from network); 1 Jul 2018 01:29:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jul 2018 01:29:22 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.25 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.25 out1-smtp.messagingengine.com Received: from [66.111.4.25] ([66.111.4.25:43005] helo=out1-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 20/65-15351-E6E283B5 for ; Sat, 30 Jun 2018 21:29:20 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id BB1A6211EC for ; Sat, 30 Jun 2018 21:29:14 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Sat, 30 Jun 2018 21:29:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=7hi6tpCOLMXbDRmo2xAAP8gDG8URE khlsHbl8k/+SQc=; b=GPTtS0FkTsQ+XbGIUS8DpGfJmDjLLxk7iomD8X2J/1AVg Bnea0HOinybLCXcQqtgSBct9Xjmzk+xU8UzeC6jLfVkzNSvl0M69XrZEopQJ1/IQ 1zUDDrZWaNBIkTXtBySDee5EtXeUzH70izs6EUO1P281mp4A+P955B4z92bAaOs5 Txq/xNYBZK7AuqbM4lY9kajKG7PEyvQknW1hxJhxRblORyFBR2je58UKGIGFgiWJ wlsla4o3Gt+nOqeFCvqa3w1TsfQhtQw2GQCDMZBrw8aMYsFQEckKCTt88GSAJ1N+ 5I3jN9pKiwU1TmDDSCLHoftxvuzHtRxW70frTQ74w== X-ME-Proxy: X-ME-Sender: Received: from vulcan.localnet (216-80-30-152.s3222.c3-0.frg-cbr1.chi-frg.il.cable.rcncustomer.com [216.80.30.152]) by mail.messagingengine.com (Postfix) with ESMTPA id 60AE71025C for ; Sat, 30 Jun 2018 21:29:14 -0400 (EDT) To: internals@lists.php.net Date: Sat, 30 Jun 2018 20:29:13 -0500 Message-ID: <10630585.pfV4cjzRZt@vulcan> In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart4030138.PNvAGqfR0n"; micalg="pgp-sha512"; protocol="application/pgp-signature" Subject: Re: [PHP-DEV] [RFC] User-defined object comparison From: larry@garfieldtech.com (Larry Garfield) --nextPart4030138.PNvAGqfR0n Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Thursday, June 28, 2018 9:47:56 PM CDT Rudolf Theunissen wrote: > > In this case, the order of checking to see what method to call will also > > check > > for type compatibility. That is, $f < $b checks Foo::__compareTo(), finds > > it > > doesn't match, and so calls Bar::__compareTo() instead, which does. > > I'm not sure if I like this, it's a bit non-deterministic isn't it.. that > the comparison function > called can be determined by the value being compared? While I'm not > disregarding this > idea entirely, it's another addition we can add at a later stage. > > It would be a bit of a juggle internally, to hold on to the type error > while we attempt the > second call, and if that fails, we throw the type error of the first > attempt? Thinking on this more, I think we have to do it in some fashion. The current rules in the RFC say: * Check if $a has a __compareTo() method. If so, use it. Else: * Check if $b has a __compareTo() method. If so, use it. Else: * Default behavior. However, that ignores the case where $a has a __compareTo() that is not type- compatible with $b. In that case, the current rules in the RFC would imply "call $a with a type mismatch, get a TypeError", regardless of whether $b::__compareTo() would work." I would suggest the better logic be: if (either $a or $b have a __compareTo()) { if ($a->__compareTo() exists and is type compatible with $b) { use $a->:__compareTo() } else if ($b->__compareTo() exists and is type compatible with $a) { use $b->:__compareTo() } else { throw a new InvalidComparisonError (new type, extends TypeError) } } else { Default behavior } That way we don't need to track A's or B's type error, we just say "if either of these objects is opting in, do whatever we can. If not, it means we don't want default behavior." Obviously an untyped compareTo() method is always type compatible with anything, so developers can use that as they desire. > I don't understand Future Scope point 1. It... means we're already covering > > > those operators. Why is there future scope needed? > > Python, for example, has the ability to override specific comparison > operators, such as > > > > > __lt__ for <. Point 1 is trying to say that *if* we want to introduce full, > specific operator > overloading in the future, we would already have the magic methods for == > and <=>. Oh, so it's just saying that implementing __lessThan() in the future is not blocked, as that would simply get checked before __compareTo() while __compareTo() would be the first thing called for <=>. Gotcha. I'm good with that. --Larry Garfield --nextPart4030138.PNvAGqfR0n Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE/ph/GXfY8v0YwFBp4MMKwDFxYXcFAls4LmkACgkQ4MMKwDFx YXffuwf+KNAb0Qhdiu57TYyvW6DJ/P5YUu/CbEeiioOM9wHNs+D2ihrK2osJ3Qvj LEC6RSNZXE5rAKW9m86sqtv548/fvIIwYTA5p1tBswkVmK07+cGXHGOP3i4jIaTW KrgqXpzxRM9cgISE71Ko6s9XD6sXSVOWgc0aszc+Snqtc+VsFcY7iL433EFfXNFt jfcL1HuyGG1Don0psnj+SpDUy6J5Gn4JE4NIkC+I1b7ZdVp/ocR6xQJNSiuJmOER ip5K42WbHUl6/qmVZgx/Enj0Ht9m+dEuGIxuy7HhStPBkOhChJKupwFUSTr/QB1K XWpE9JnyMkmfwXsIcBCuDW/JwhKAVA== =Rx8+ -----END PGP SIGNATURE----- --nextPart4030138.PNvAGqfR0n--