Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116666 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28307 invoked from network); 16 Dec 2021 22:22:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Dec 2021 22:22:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0AA8418053D for ; Thu, 16 Dec 2021 15:24:46 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 16 Dec 2021 15:24:45 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 2525E3201C2B for ; Thu, 16 Dec 2021 18:24:44 -0500 (EST) Received: from imap43 ([10.202.2.93]) by compute6.internal (MEProxy); Thu, 16 Dec 2021 18:24:44 -0500 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-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=SzIVgu T6nTLNKnvlu8TInVjqZVq8NHYExY2HhJm2XF8=; b=DRHKnXkAm/5/Qkxuree5yK WfrBWZDlAoILl75a0Q6Irc2sSE/pqlWl/w/tOWqseNCYnOlcdsAWDWttqBECYgrV mPQu+vSrJ+mNLP59tRqbhHfk2JaUsu/ZxGIU/f50dxqu5fBs683ox81lSF9vP8bw 5zeyjdpYcpRUwUSJNbbTwJgVaWoiJ0wSEJ17xJDKkW/TdSDHY4XCfC9EA+9fZlmu 2AYKWAcVniVNmzBTB8xKtxOpn3vGc3YhwlCaZtFvrHJujA+B/iIwfdFbMBe+EoFv X2D29JAtQLJzUBtC1uOyMatuas6EWyct3Yw/yxcF7oR6kZ2VCy92I820Fm1Qvelw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrleehgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefgffek udevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 5B3B6AC03DB; Thu, 16 Dec 2021 18:24:43 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-4524-g5e5d2efdba-fm-20211214.001-g5e5d2efd Mime-Version: 1.0 Message-ID: <37dc7c09-37dc-44f5-89d5-fd3c1a256492@www.fastmail.com> In-Reply-To: References: <44b3fb4b-4693-1639-c8c0-5e17296c196e@gmail.com> <4b58c011-ed87-ba87-201d-0cf8e4116c6f@processus.org> Date: Thu, 16 Dec 2021 17:24:22 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] User Defined Operator Overloads (v0.6) From: larry@garfieldtech.com ("Larry Garfield") On Thu, Dec 16, 2021, at 1:24 PM, Andreas Hennings wrote: > I see the distinction in overloading based on the object type on the > left, vs overloading based on parameter types. > > For a method call $a->f($b), the implementation of ->f() is chosen > based on the type of $a, but not $b. > For an operator call "$a + $b", with the system proposed here, again, > the implementation of "+" will be chosen based on the type of $a, but > not $b. > For native operator calls, the implementation is chosen based on the > types of $a and $b, but in general they are cast to the same type > before applying the operator. > For global function calls f($a, $b), the implementation is always the same. > > In a language with parameter-based overloading, the implementation can > be chosen based on the types of $a and $b. > > This brings me back to the "symmetry" concern. > In a call "$a->f($b)", it is very clear that the implementation is owned by $a. > However, in an operator expression "$a + $b", it looks as if both > sides are on equal footing, whereas in reality $a "owns" the > implementation. > > Add to this that due to the weak typing and implicit casting, > developers could be completely misled by looking at an operator > invocation, if a value (in our case just the left side) has an > unexpected type in some edge cases. > Especially if it is not clear whether the value is a scalar or an object. > With a named method call, at least it is constrained to classes that > implement a method with that name. The RFC covers all of this, and the way it works around it. Absent method overloading (which I don't expect any time soon, especially given how vehemently Nikita is against it), it's likely the best we could do. > In a class Matrix, operator(Matrix $other): Matrix {} can be declared > to always return Matrix, and operator(float $factor): float {} can be > declared to always return float. > However, with a generic operator(mixed $other): Matrix|float {}, we > cannot natively declare when the return value will be Matrix or float. > (a tool like psalm could still do it) I... have no idea what you're talking about here. The RFC as currently written is not a "generic operator". It's operator *(Matrix $other, bool $left): Matrix The implementer can type both $other and the return however they want. That could be Matrix in both cases, or it could be Matrix|float, or whatever. That's... the same as every other return type we have now. --Larry Garfield