Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115662 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21684 invoked from network); 8 Aug 2021 06:43:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Aug 2021 06:43:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B7C551804AA for ; Sun, 8 Aug 2021 00:13:31 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 ; Sun, 8 Aug 2021 00:13:31 -0700 (PDT) Received: by mail-lj1-f174.google.com with SMTP id h17so7460430ljh.13 for ; Sun, 08 Aug 2021 00:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=21/wFWTAulgloa10g8nxIkB5RZz+XiY5kIj5YlUht30=; b=p8oD3myXTXANvEDBFuRGzeu9dNRAxGxuTHx4754oBVnBYxgnlwFL+R4lHJ9Dy1qzhE vVIcvSnUUgaM81+zKRusA3clieNA4nCZT3217w6WN/3cnh3MXWnpcm8fu4ZUqIRUacZY D2r0GTd0VoE10SXnj+jCWEsKVALMph85bpoR0KVjwnxkLi4q2cAvK6h2lcorbmDRS/v7 Hl77FB0lMIDxxm9jy774WjdRenuskXXIC2wEGnExpsdfOYIQYLUZljXc2xgdKS/rBtps kntpwgNvrgAI9yadqNLF0pOCeOZku3+fB7FQ8yRst7zhtoIH1IjaSJj/mwm0aYro3Bnd LRYQ== 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; bh=21/wFWTAulgloa10g8nxIkB5RZz+XiY5kIj5YlUht30=; b=eMECH9X9tPyQaxyAw/2fnV/MGi1BiEvlLgIGryeqXuc2E1rUQ+48LzHJJ9OWuuA/WC xkiGjEFggOsddawsRBrb1ND2g8IqKE2Sf+Awsuzg/IOhoDBUmNLJXwv89c3rzMARfdGE 2lLzm3Emjazlq0LApbmCAet/yw3S5xMqonEoLvpFBSJE4FsaURdPbrrJLVtOojdbXctE mwCtAZNR9blcbd90HHFkgkd0jeQj+Q3k8WDuu8G4IW4R5esZETwf0Fgg246sbO5NHEYL kCEbv51SEJ8k8PwWUEcbsb0hEboImXYJaW0MqaAIChPhLHdtSvY7HAY9evoCpk3DIqZf qMOg== X-Gm-Message-State: AOAM5313cfMV9gUVc8dpVypQnBxAiavEOrL0lac8a8AWT4y2sX5oQUTU OeCN96qHY9SUTfacgrpwzMnMvsBma5W5zZIidA39OuBSM9o= X-Google-Smtp-Source: ABdhPJzxKLxJF8z1GsmZ+AjQrkXwJpqsk7LZN82Dv4MR8M1vRne29b/0z5fb7I5LCr3FdQWkPp3nQRIpeC8Z/49NhMg= X-Received: by 2002:a2e:9e4a:: with SMTP id g10mr11938330ljk.54.1628406809160; Sun, 08 Aug 2021 00:13:29 -0700 (PDT) MIME-Version: 1.0 References: <94696d46-c4e6-406a-b859-89144bff31bf@www.fastmail.com> In-Reply-To: Date: Sun, 8 Aug 2021 00:13:31 -0700 Message-ID: To: Dusk Cc: php internals , Larry Garfield Content-Type: multipart/alternative; boundary="00000000000068ee8905c90701d6" Subject: Re: [PHP-DEV] Revisiting Userland Operator Overloads From: jordan.ledoux@gmail.com (Jordan LeDoux) --00000000000068ee8905c90701d6 Content-Type: text/plain; charset="UTF-8" On Sat, Aug 7, 2021 at 8:26 PM Dusk wrote: > On Aug 7, 2021, at 15:28, Larry Garfield wrote: > > As an example here, time units. Adding two hour:minute time tuples > together to get a new time (wrapping at the 24 hour mark) is an entirely > reasonable thing to do. But multiplication and division on time doesn't > make any sense at all. Or, maybe it does but only with ints (2:30 * 3 = > 7:30?), kind of, but certainly not on the same type. > > This touches on another important question -- how do we plan to represent: > > 1) An operator which is only applicable when an operator is used on two > dissimilar types (e.g. TimeTuple x float)? > > 2) An operator which can be applied to an object, but with a primitive or > otherwise non-extensible type on the left hand side of the operator (e.g. > float x TimeTuple)? > > 3) An operator which can be used with multiple types, but whose meaning > and/or return value can change based on what types are used (e.g. Matrix x > Matrix vs. float x Matrix)? > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > The short answer is that all three of these concerns *must* be left up to the userland implementations. Our job, realistically, should be to provide a sane and consistent way for their implementations to accomplish this. But truly, for most of these conditions the interpreter can't make enough assumptions about the purpose to make any meaningful contribution on questions like these. Because of this, as far as actual implementation goes, I was gravitating towards one of two possible formats: function __op($rhs) { } // Binary operators function __op() { } // Unary operators In this implementation, an object could *only* overload the operator if it was on the left hand side. There are some advantages to this. It simplifies the cases within the do_operation function that would need to be considered for instance. function __op($pos, $lhs, $rhs) { } // Binary operators function __op() { } // Unary operators In this implementation, the $pos argument would be 0 if the called object was on the left, and 1 if the called object was on the right. The right hand side would obviously not be passed for unary operations (though there aren't any unary operations that I plan to implement in this RFC). The major advantage of this implementation is that the code which is most aware of the context and meaning could fully handle the situation, regardless of whether the object was on the left or right. This would allow us to provide something that is *more* commutative, even if full commutativity isn't desirable for the reasons I've outlined earlier. Jordan --00000000000068ee8905c90701d6--