Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116629 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43941 invoked from network); 12 Dec 2021 17:56:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Dec 2021 17:56:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 949321804E3 for ; Sun, 12 Dec 2021 10:58:12 -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.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, 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-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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, 12 Dec 2021 10:58:12 -0800 (PST) Received: by mail-wm1-f42.google.com with SMTP id d72-20020a1c1d4b000000b00331140f3dc8so10309623wmd.1 for ; Sun, 12 Dec 2021 10:58:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:from:subject:to:references :content-language:in-reply-to:content-transfer-encoding; bh=zyHc39CgnjVINqcXiX0jcRBz5aYmmMlwPvvNobZjHYo=; b=PCO8LyObwcJD7o4GDLD1WKxujn8LcqQOShv9BC7E3u8Y+vzddkb9pZJNiug5jdrnYL iF+/9Kqh7rH4uURQeHDZG+k4uThO2UDecjsTT+fGYhlzijfNGGNq6tr3RXcwTlqGj9vw ZBwAfyB8MWiLaRWsTLfGnlXkEaXKkFcsTthLn9klmFiNpkUM+8drrMZrb2pJrlYPNGep SfqsDLzGCPOwQtSesXzo8KhzMreua2EWo4o9jWdrI8OnW3oMVqBmH1ZGXmVOQgrF26Xu qqfQxnwffiqebjnTuxkLosgXpluIuI8eGrdIyilJIhzm1baxXB+XKC4wlbY2oow96KN0 i+bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:references:content-language:in-reply-to :content-transfer-encoding; bh=zyHc39CgnjVINqcXiX0jcRBz5aYmmMlwPvvNobZjHYo=; b=CJNj9YKbqA02xGagYLcRPasavc9HQ2/tLz8CsSKqkEV1fFvn4/KF/U+rfUB5Mezqo4 N7fujCMnyl7vaiFXgAFkzhoKoSDQ+iHn1fRuAqu/oWbW6PTT6H91IZnDgSOzLLmgbOTG cICPqMTNGaGjOs848fBX2DjhsUaRat+NBy+pK7PI8q0U71UNhfvOwEDRLxGamLB2OE6v IY3njigNaLtipkvTOoggqRv14GCoLCX1yULjEmiNI9+UN4QcHnAoIVz2wgDWz6CbMxqB CMfjKWMn6QoSUwiOJMRuoUEYdDPU82SLmGLYaOuZqdiPOhDJ7yoEnjBJCkdAqB+g1chs FfmA== X-Gm-Message-State: AOAM532O/iM+ekr03JR4nmXu4k72B2QWmsXkSCTiQmfLKpmnSy5pEJWZ T9Du0Iu+6QzcKr1YcA5AwiTYhh19hOg= X-Google-Smtp-Source: ABdhPJwMwUB/DOl6yESvRs92ghguFUtaw28pWVXbsWWusX46lKxcKT8Pzo2bH/Cl/pQslsKksA16pQ== X-Received: by 2002:a1c:6a04:: with SMTP id f4mr32254822wmc.56.1639335490926; Sun, 12 Dec 2021 10:58:10 -0800 (PST) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id j40sm4901214wms.16.2021.12.12.10.58.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Dec 2021 10:58:10 -0800 (PST) Message-ID: <69e19527-50b6-327d-fd01-18c003f21c71@gmail.com> Date: Sun, 12 Dec 2021 18:58:08 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 To: internals@lists.php.net References: <4032cbcf-a1a5-4e16-8563-cb24f7abcf17@www.fastmail.com> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] User Defined Operator Overloads (v0.6) From: rowan.collins@gmail.com (Rowan Tommins) On 12/12/2021 18:29, Rowan Tommins wrote: > Perhaps we could use an Attribute to bind the operator to the method, which would also reduce the impact on tools that need to parse class definitions: > > class Collection{ #[Operator('+')] > public function union(Collection$other, OperandPosition$operandPos) {} > } > > An interesting extension would be to have an optional argument to the Attribute which binds separate methods for each direction of arguments, rather than exposing it as a parameter: > > class Number{ #[Operator('/', OperandPosition::LeftSide)] > public function divideBy(Number $divisor) {} > > #[Operator('/', OperandPosition::RightSide)] > publicfunction fractionOf(Number $dividend) {} > } Sorry about the whitespace mess in the above examples; this may or may not show better: class Collection{ #[Operator('+')] public function union(Collection $other, OperandPosition $operandPos) {} } class Number{ #[Operator('/', OperandPosition::LeftSide)] public function divideBy(Number $divisor) {} #[Operator('/', OperandPosition::RightSide)] public function fractionOf(Number $dividend) {} } Regards, -- Rowan Tommins [IMSoP]