Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115771 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52235 invoked from network); 23 Aug 2021 08:38:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Aug 2021 08:38:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EC0FA1804BD for ; Mon, 23 Aug 2021 02:12:33 -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.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-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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, 23 Aug 2021 02:12:30 -0700 (PDT) Received: by mail-ed1-f47.google.com with SMTP id q17so3276798edv.2 for ; Mon, 23 Aug 2021 02:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=2xexoZpyae5zJybFzFePloG0nR5uXIp/k/AJNJi7BUs=; b=W7vJN3qnYnS1wWtkzxnSPE8mDv19nZqLmaA44UJxYZc5Rd1UFm3ErJPuKnJczUV/Qt U7Hushj7DVfvvC/y5qr6FpAKkyjyWpnG5kDsqYB15LxRkljFqcmVDI2DEezNhEZxtm5C oZRajP2gVhM8vyO1W0fW8h7hExJA8vsl68qqKgsfzJ1kAvq15GWEIJcsDhF9pYPRiiJI JSOt+qN/iBcm7yv8LJJQEWl5Esj/+4VdARN2iWrSx1TjYT/xG15pgVxR+1xvDd6gHvId y4lCPmz2a+U/7OY954Z4AJrawSuagccPnb/oFBBQHpbaKz4SJgE5vcot02QPDsY18LPG NCiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=2xexoZpyae5zJybFzFePloG0nR5uXIp/k/AJNJi7BUs=; b=TExn0y2r0KoFa/LEgjuXUij4+moAZgp5jwoRQfnR/g0XOZaI1Yz34h+k2KnK8Vwzmm e8YB8tU1NJO5Z1kBgfGGe5MEbul3wbVIFhRhWp1YZ9DOnHsu23LVFcDOevXGbDfY3st6 F9JKRS8WGV+CwTTQDUgnAhv/tOOEOff7hUao/8cD1idJb9rj9FGy/WyWEeVAQU/3qop7 3OQGRlxlQtjgiWXxEJvh6jz/4y81RWe52oQgxxJ4eMeS1hiFfoCPswmiFPQJLxhnG4L6 usVg/uTjFq3E0JQzqngMm6PaT7y+vdz6lwU83YvjIEYyf8ljEuaYQOGZJdYAirijTHxo HQIA== X-Gm-Message-State: AOAM531SzAr3+erjyo/QGyBwdb9EBIH8Ym2ImJu+DKvuHkgTJFzEDJlZ usSpMmZvsrle6YCzC9DumsPtq7YraWY= X-Google-Smtp-Source: ABdhPJwr+UGOQiGRZv825dwgiozB/FwcRcrfE1E8WVzQ8h6OEpY8huPwTKJ5b7KTsgLUBTFRaX/45g== X-Received: by 2002:aa7:d947:: with SMTP id l7mr3231399eds.105.1629709948446; Mon, 23 Aug 2021 02:12:28 -0700 (PDT) Received: from ?IPv6:2001:983:6fc5:1:95b6:6e33:50c8:c1e9? ([2001:983:6fc5:1:95b6:6e33:50c8:c1e9]) by smtp.gmail.com with ESMTPSA id o23sm8906586eds.75.2021.08.23.02.12.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Aug 2021 02:12:27 -0700 (PDT) To: internals@lists.php.net References: <94696d46-c4e6-406a-b859-89144bff31bf@www.fastmail.com> Message-ID: Date: Mon, 23 Aug 2021 11:12:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Revisiting Userland Operator Overloads From: dik.takken@gmail.com (Dik Takken) On 08-08-2021 09:41, Jordan LeDoux wrote: > Off the top of my head here are some of the use cases that I think benefit > greatly from this: > > - Complex number objects > - Fractions objects > - Matrix objects (math) > - Vector objects (math) > - Time/Date intervals > - Collections > - Arbitrary precision numbers (which are usually represented as a string in > PHP) Hi Jordan, I would like to point out another interesting use case that I have seen in the Python world: Query builders. In that use case, operator overloads are used to create database filtering expressions for example, allowing one to write: db.products.filter(db.products.price < 100) Here db.products.price is an object representing a database column implementing the __lt__ method, overloading the < operator. This method returns an object representing a database filtering expression, which gets passed to the filter() method. So basically, this would allow for writing expressions in plain PHP and have them translated into other languages under the hood. The use case does require that operator overloads are allowed to return any kind of value they wish. Regards, Dik Takken