Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116626 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39285 invoked from network); 12 Dec 2021 17:27:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Dec 2021 17:27:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DE2481804B5 for ; Sun, 12 Dec 2021 10:29:14 -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-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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:29:14 -0800 (PST) Received: by mail-wm1-f45.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso12640577wml.1 for ; Sun, 12 Dec 2021 10:29:14 -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:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=4wwmI3Zytgscj+X1eq+isfmhVZXArMTGFfAm6FDJSgA=; b=KLYE8LDqdXrTrsNJbfLhtWq12osDMrougVEbZkJx4Dyy2rmWTMsNA6HNSh5RUy8hn6 7j7HEaGjfXQiMjGEgU1SQryI1oWsOc+fTfW9xK5jXHluo2yBlKgUsAKU6Ni3o1Hz7vjs S5+pWyozIN0OG5jAC4jPmTV9KVsdqbG9YCM5JP07A4hoIlyQGrmZ4z+Z+reMUG1Ug2TJ +fBdHq9eqF7xdIcuJT8bfItW+kEf3YOEOAoPXvPjWjaQDzsAtJZmrtvEssTZZitUOb+z kgEX3yKCUfk1gayQLSTlPLVu8h4sKiBKtpVm7o9xkpGmNjb/HGzVwpkWRQf1nyL1U1or BBtg== 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:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=4wwmI3Zytgscj+X1eq+isfmhVZXArMTGFfAm6FDJSgA=; b=Y0wt62S4vi9oOaNNk5uHCTQ/v/zPKnsfLtYYaAHnOaTAHNljKWnG0cPXR0/hm0EkSX Bc2UQIv2A/y6KAEvKZ6fMRwqAIozD5zY3PRK16tshqt19IXXLUZOULg/qwH6hGgSy4JA 63RDrQZOrC4DN3Cp1mH2Nxq7Q5eqDrteV3FkGfDpgw9N14lH/6DsnZStZsXMpI5Wf5SX qVXmz4FDRQXT9MGbrVixLCLOGHA+PSZkpf0sClLVjfI0mS0Yve2GZrf/DzveTw3sKk2a tJ6hzfrMaYQ2oAISzu9BUnzItOB/pmWWEoySGcdM13clWXB+kpGBkr3XYXNjbRlXCGkU F6Zw== X-Gm-Message-State: AOAM532Mh966x5KAJ3RJOL69o4ppEJ0qwpXMb/zgaPjArrya6MpK49+S 09WX+Zq/cXwyAKfhOTESy7Wc8aevTgQ= X-Google-Smtp-Source: ABdhPJyf5ytDeB7Kd4hNoBJtnvMtZg7+e5oqhBflPREbN2OgLO51iGiuL8BvwEXPwZbd96xfq08bMw== X-Received: by 2002:a1c:2053:: with SMTP id g80mr32363736wmg.3.1639333753100; Sun, 12 Dec 2021 10:29:13 -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 d15sm10600323wri.50.2021.12.12.10.29.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Dec 2021 10:29:09 -0800 (PST) Message-ID: Date: Sun, 12 Dec 2021 18:29:04 +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 Content-Language: en-GB To: internals@lists.php.net References: <4032cbcf-a1a5-4e16-8563-cb24f7abcf17@www.fastmail.com> In-Reply-To: <4032cbcf-a1a5-4e16-8563-cb24f7abcf17@www.fastmail.com> 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 17:32, Larry Garfield wrote: >> The only mitigation for unnecessary complexity I can think of is to force >> overloaded operators to be "arrow functions" to encourage only minimal >> code, e.g. >> >> operator +(Number $other, OperandPosition $operandPos): Number => return >> new Number ($this->value + $other->value); > I don't think that would be possible. As many of the examples in the RFC show, there are numerous cases where an operator function/callback/thing will need branching logic internally. Even if we did that, people could just sub-call to a single function which would be just as complex as if it were in the operator callback directly. I don't know if this would actually be helpful, but you could *force* the operator definition to be an alias for a normal method. That would (at least partially) solve the "dynamic call" problem, because the underlying method would be available with the existing dynamic call syntax. 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) {} } Regards, -- Rowan Tommins [IMSoP]