Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116652 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 66151 invoked from network); 16 Dec 2021 02:59:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Dec 2021 02:59:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 766601804A8 for ; Wed, 15 Dec 2021 20:02:05 -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-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 ; Wed, 15 Dec 2021 20:02:04 -0800 (PST) Received: by mail-lf1-f44.google.com with SMTP id d38so2666937lfv.0 for ; Wed, 15 Dec 2021 20:02:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xN6Fa1xlFa49R5eKXlkfsZuKTXXnqkePLP+1CNFhyh8=; b=A6rNumqND048Tp6v2IINGCwDfYJqfvcaZukILc+6hIuFFUuoU/xGpHwRiOqPnkmcNf 2wSvdLbnhxDDjTJZjSalooU+0vbW7HL3qby/FEGuJrCFdbnMQs4meyXUs3O/G635QV5X OTvsIDkSXsEYPkyOhoRSmxA7CkijNBfG6x0UsOYA3cgQFjgnj67/pbBQi/c+fCiDjCxH 6hpCRZZtSrybrgQTg740WkbSV4ygfaRDppnALn11ea7oEe6qVmJzpOx+rAZkXE6ow8KR vmGZv/k+mZ3wVVO/vVsex1F7xcV+tkSQ61k+68wLvbXj5kjFi/Zz9LMVX16pTu3nZ7JZ hlfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xN6Fa1xlFa49R5eKXlkfsZuKTXXnqkePLP+1CNFhyh8=; b=3ftvs9kOfT+y2VxNDoH21kqNfEfsWatCki83rr3cUKiuonDKtxCXmN46KJvrZ0snzE PIwCVWqPnNGK7tk6N00JOVy3HditGn7px1Asd+cTrq3tqK33OHuJYxELF7J6utk8VNDC RGtOOc4WTVAN/5xRav7EJGwp1J0ZfT1Au4hIAMFAQE9WcpKPhq6H2ipPe3iCF3kQ2fYo 8X3mns7zAu2bJM/PAVrNi3sH+wrdJ0p4AALX42f/6kaf3chxq+enzVLeYW3I/jx3+Jp3 rHHa2K4LnHL2ZIi14cocfChVa3VAe9ZV2bP5Eb44QTt2e0uQJoRcz4HStWwNadFJP4OY AmyQ== X-Gm-Message-State: AOAM533njWqC+R8M+7XUkqL8cjmH/CNj4Ui5zJJdjmLOVsB8LSAzEHIL ByxlRPiDkOt336zPP1bGnckOJ78GG93rABGeJWI= X-Google-Smtp-Source: ABdhPJz5KMTB8WVcCLzZpoiD822cx3XEbwAz9IU64aN8PfO5QkI8otKfUdxnQH3sMnfPd9BCqm2d40JS83VdQDbjqfo= X-Received: by 2002:a05:6512:114e:: with SMTP id m14mr12953251lfg.418.1639627323141; Wed, 15 Dec 2021 20:02:03 -0800 (PST) MIME-Version: 1.0 References: <44b3fb4b-4693-1639-c8c0-5e17296c196e@gmail.com> In-Reply-To: <44b3fb4b-4693-1639-c8c0-5e17296c196e@gmail.com> Date: Wed, 15 Dec 2021 20:01:50 -0800 Message-ID: To: Dik Takken Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000028f32605d33b7ca2" Subject: Re: [PHP-DEV] [RFC] User Defined Operator Overloads (v0.6) From: jordan.ledoux@gmail.com (Jordan LeDoux) --00000000000028f32605d33b7ca2 Content-Type: text/plain; charset="UTF-8" On Wed, Dec 15, 2021 at 7:04 AM Dik Takken wrote: > Hi Jordan, > > Thanks a lot for your work on this RFC! I like the direction this is going. > > One thing that may be worthwhile looking into is the query builder use > case. I mentioned it before: > > https://externals.io/message/115648#115771 > > Basically it would enable using plain PHP expressions in stead of > strings. So in stead of > > $query->where('product.price < ?1')->setParameter(1, 100); > > one could write: > > $query->where(Price < 100); > > Here Price is a class that represents a database column which has a > (static) overload of the '<' operator. The operator overload yields an > object representing a database expression, which gets passed to the > where() method. > > In general I don't like this sort of clever construct which makes one > wonder what on earth is going on. The reason I do like this particular > use case is that it can simplify code and enable static analysis of > query expressions. > > Now I'm not suggesting to support this creative use of operator > overloading in the current RFC. It may however be useful to consider if > this use case could be supported by a future RFC in a backward > compatible way. Perhaps the RFC could mention it as a possible future > extension. > > Kind regards, > Dik Takken > This is not a use case I highlighted because it's one that would be difficult to support with this RFC. But as you say, it could be a good future expansion. In particular, putting a query builder object into core with some more advanced overloads built in may be the best way to accomplish this, particularly if it is built with the idea in mind that the entities themselves may also have overloads. I can certainly add it to the future scope of this RFC however. -- RE: The operator keyword and operator implementations being non-callable. This was a limitation that I purposely placed on the operator keyword, as I didn't like the idea of allowing syntax of the style `$obj->{'+'}();` or `$obj->$op();` and I wanted developers to clearly understand that they shouldn't treat these as normal methods in the vast majority of circumstances. However, it seems this is one of the largest sticking points for those who would otherwise support the RFC. To that end, I'm considering removing that restriction on the `operator` keyword. If I were to do that, you'd no longer need to wrap the operator in a closure to call it, though the parser would still have problems with `$obj->+(...);` I suppose my question then would be, is this an acceptable compromise on the operator keyword? It removes one of the more annoying hurdles that Danack mentioned and that others have pointed out, but retains much of the benefits of the keyword that I expressed in my last email. Jordan --00000000000028f32605d33b7ca2--