Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115653 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73505 invoked from network); 7 Aug 2021 17:12:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Aug 2021 17:12:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 260E2180088 for ; Sat, 7 Aug 2021 10:42:05 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f49.google.com (mail-vs1-f49.google.com [209.85.217.49]) (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 ; Sat, 7 Aug 2021 10:42:04 -0700 (PDT) Received: by mail-vs1-f49.google.com with SMTP id t29so7385853vsr.5 for ; Sat, 07 Aug 2021 10:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=sx9ncPL2LZ6PBAMt6NfO+RzQ7F/73Fg8JMDFGadFwXM=; b=P6r+dW2TCNCwTwyspKynSlkmgxwYarMVcjxqZ8SrHPz7+z1VdDf5dK3dWT7bxh5aQM z5HnYMPKrwVDYJew4n3jopTEIGy4YQn11d6U+uOkBdHY69XP8AVbDKKBeKarZp5QWcAW AlHYY9albpQ0s1Y81k54l+BETSlImbM9zK6NdFI4gX4ESaI4h9NZWBSiC/X+/b7qzYR4 DZPzlx1tZ89CUiGYTb5KsSut2GBKDNQdT9OwMdyOzuMgCzoGiTqiX3XOj4LQjC2xR0o+ 9k0Raqmpv62OCT9UUxK6Ar5PMj5qM1PpTvN/ccAqDnH2xr7NDp3uOil/yz2FaA07ykJG pIJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=sx9ncPL2LZ6PBAMt6NfO+RzQ7F/73Fg8JMDFGadFwXM=; b=uMXXi4kCYkKupaBb4EeYatDA0lEGYIIvjhuEh39qQfSFsBOu7R0ylzw3EaN4RnR9nu xZHfVJxJAIQztE+3uxRB7tbHg+XYxNURxq1FCdWInAktIxQvYNforiI8FpM4f8NUjpik /G4wYJSUXmSNDePuLx0n6vr4w2ws69oku0VGI6yKZDkftr0NUDqqCQdY97OgB9Fk1VLM sDuc7hRRPUyZkRcFz+cMTtTSbWUbBCZSpP6xSeiVzBOW8VYJLsXFEtSH1tPxpKzykHye puRsO4HdyQCrbiqub5f5qrbIO9YzxnX0a89NowPZqkJiAVf1PrwY7KgS47sVVyW0nBq0 UbIg== X-Gm-Message-State: AOAM532d2eSAUR6Nr2G1RYSE7+3CrzFpUs9qd8RJpoPAaVstN9A36EBp FbHVdMiI4ZlA7840wfbZKXWUlko6z/eJK/RjXd9OvA== X-Google-Smtp-Source: ABdhPJz7L6oj6CqWSgBLhYg7+iTXOlAJNEyEUTOaj1fBIRFwIiexzRtzXxVY3ydsW7nnhxTidVx7PA/lVKwhLzMeXx8= X-Received: by 2002:a05:6102:108:: with SMTP id z8mr13457953vsq.37.1628358123856; Sat, 07 Aug 2021 10:42:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 7 Aug 2021 18:41:52 +0100 Message-ID: To: Jordan LeDoux Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Revisiting Userland Operator Overloads From: Danack@basereality.com (Dan Ackroyd) On Fri, 6 Aug 2021 at 17:34, Jordan LeDoux wrote: > > I was considering working from Jan's previous > implementation with these basic changes: That may not be the best place to start, and that something more similar to the previous (unvoted) RFC may be better: https://wiki.php.net/rfc/operator-overloading In particular, the problems with the approach in https://wiki.php.net/rfc/userspace_operator_overloading is that having a function return a special constant when unsupported types are used is...just not the right approach. The function shouldn't be run at all if the types aren't supported. Having to understand a block of code, to figure out what types it accepts, makes code hard to reason about. Although the union types RFC had passed when the userspace operator overloading RFC went to vote, the ability to use union types wasn't taken advantage of in the RFC. Listing the types supported as a union type for the parameter like: class Order implements __AddInterface { public function __add(Product|Discount $rhs) {...} } is easier to reason about, and would throw a type-error consistent with how unacceptable types would behave for other function calls. I personally find having the functions be defined as static, with the first parameter being the left hand side, a bit weird. It makes the code quite a bit harder to read imo*. > I feel like the right place to start is to limit > the RFC to only the mathematical operators at first. > ...something like MathObjectInterface I agree with Larry and Scott, one method per interface is a better approach. But defining all the interfaces in one go is probably better, even if the implementation only supports using some of them. Doing it like that means that when new operators are implemented as overloadable in PHP 8.3, people would be able to write library code that takes advantage of those new operators that works on both 8.2 and 8.3, without users having to define the missing interfaces themselves, even if their app code isn't able to take advantage of the newly overloadable operators until they upgrade to 8.3. cheers Dan Ack * This was mentioned in the RFC: "By passing both operands to the handler, it can decide between the cases on non-commutative operators ($a / 2 vs. 2 / $a), which would be more difficult when only the =E2=80=9Cother=E2=80=9D operand (besides $this) is passed.", but I can't se= e an example of that, and I don't understand it. Perhaps a better explanation would be enough. Though also the behaviour for associativity mentioned in the previous RFC https://wiki.php.net/rfc/operator-overloading#associativity isn't mentioned in the 2020 RFC and there may be a can of worms in that.