Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108809 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88000 invoked from network); 2 Mar 2020 16:37:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Mar 2020 16:37:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C8DB1804DD for ; Mon, 2 Mar 2020 06:56:06 -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.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-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) (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 ; Mon, 2 Mar 2020 06:56:05 -0800 (PST) Received: by mail-il1-f170.google.com with SMTP id e8so4875183ilc.13 for ; Mon, 02 Mar 2020 06:56:05 -0800 (PST) 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; bh=4TR7QNa/dtvUQEwuzf2ilWP4vZWoz+Uk3L9T1DIFa7I=; b=Av7wDG0mW7sIDP9Rq/SPPZ9HmDlO4F79q9KkWK2Sm+9iR9lae4HiXgmuF/W5i0l8QB z5rRKiRUPJvs+8CA8WfevGFcyF9T0xWZ6qUJqceHLdJ7RudMcxxScUUW9miYLldgRBr0 /rb02M7XZl7h5KRMmIiDxJWGqsp5ehLEj26WxKM8AWziyMm1C1own6LR6STjk2TVuwla GOGFkFUC+s1iWyhuntBT9Tz70++SLOxNxYgPwlavBVDmldSlTtlre7/CruOe70fUAfCs d4h5aSj948yObCvxbSRqXy2FC6Lv/pK/DNYHkL0AERPzAmMETjjQidJ5GbZwhwePXLzw KNMQ== 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; bh=4TR7QNa/dtvUQEwuzf2ilWP4vZWoz+Uk3L9T1DIFa7I=; b=NzfKgM2yjSZ5z4oa6/Ojvmwt+menVjsDzBuRwChbGzWXJvMDxQ5N+UNr4Y5iAHV5SR Pp3RltRcANz79X59tNH1AhomYkZDSZB3faoIEV2GBHe9Af8mmu+fPcsylyPXSkZzQ18p b+MxH6xbB7+MjU9FLBhA9PyKWasaSL/s+OYHewX7AfPtoMVpEaNG2PerjVMMz8P+ccmw 1fDZV162Jt/WdqhVPhxHFmzrbQDS1kb0RXkPg0GqLih3Z0+SUofTW9Vng83R0RwC75kn DtDoVtCAjAnv/b5U1dE27O7l0Vw4sCW15A0X3pg3fOl/ZRCdztUNHT8YtpCegiCBMw93 PXIA== X-Gm-Message-State: APjAAAUaiHig3KwG9opLzazftmAjrJz4GcPAniilUxHmIRUf6OWpdusm 63GlmLbKph6ofxu7TY9lSNFPzA1x/4piUsVceFHExrAZ X-Google-Smtp-Source: APXvYqyqoYCUVCZ0Di5MxafdEXE++uzv7cK5gFpIG2/54toWfCgDt+KHZc2ZhrHN216fOopBWXKZ54iT9i82qh401w8= X-Received: by 2002:a92:91c7:: with SMTP id e68mr17247019ill.161.1583160964595; Mon, 02 Mar 2020 06:56:04 -0800 (PST) MIME-Version: 1.0 References: <005101d5edae$7b7c3e10$7274ba30$@gmx.de> In-Reply-To: Date: Mon, 2 Mar 2020 14:55:53 +0000 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000eac4fe059fe0621c" Subject: Re: [PHP-DEV] Re: [RFC] Userspace operator overloading From: rowan.collins@gmail.com (Rowan Tommins) --000000000000eac4fe059fe0621c Content-Type: text/plain; charset="UTF-8" On Mon, 2 Mar 2020 at 14:30, Nikita Popov wrote: > > I think others have already expanded on why it's not possible to group > operators in a meaningful way. The DateTime example is probably the most > pertinent there, in that DateTime + DateTime is illegal, while DateTime - > DateTime is legal. If we can't even require both + and - as part of one > interface, there is very little we can require. > In my opinion, not being able to overload both + and - is a sign that the class is "abusing" operator overloading, in that it is using it to build a domain-specific language, rather than truly overloading *operations*. An overload of "DateTime - DateTime" wouldn't represent "subtraction" for precisely the reason that "DateTime + DateTime" doesn't make sense - DateTime doesn't follow arithmetical logic. Instead, it would represent a domain-specific definition of "difference". A more "correct" operator overloading would be DateTime + DateInterval, and its inverse DateTime - DateInterval. The common consensus seems to be that we don't want domain-specific overloading (the example of << and >> in C++ has been mentioned several times). If that's the case, then an interface that prevents you implementing DateTime - DateTime seems perfectly legitimate. Regards, -- Rowan Tommins [IMSoP] --000000000000eac4fe059fe0621c--