Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116811 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48445 invoked from network); 5 Jan 2022 08:29:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jan 2022 08:29:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BFAB21804E3 for ; Wed, 5 Jan 2022 01:36:38 -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=-0.2 required=5.0 tests=BAYES_40,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-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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, 5 Jan 2022 01:36:38 -0800 (PST) Received: by mail-lf1-f48.google.com with SMTP id bp20so87833184lfb.6 for ; Wed, 05 Jan 2022 01:36:38 -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=2bb863FRgEX93VOawz5KWG5/+UMBIiTjQa2/GrsqSHI=; b=eelXw/M7LXM3dTdu3SUqmoqj03VIN3v0hPqX+097HWqwqQi4bdnWnOCjfyi3Y3VTVw TXo+zX1DIfHDXhdZhJMEIIP7cfNJTl/2BEf5wc6LOTMAdut/pLLMZg9c8lV/meDdVMYS EVDRqI15zJH6N9YLsgcMCLPrZBdnQQ8sanT03+Z4CKBVDz8lslMJGf7KpJx1SgE/WxS+ Q5+gngxJzAyfQJG7lVit1++4NyShnI9AtjQZ5QCKUmbyraKjc2Veyg3E1PFI5SnuPiPH 716LkdxkgAALQ0KRhcWTs+M1AxNLJhd7VrlmNCfPa1qTsJ8vyf5oaSfv5uGPTas1I9OT vOUA== 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=2bb863FRgEX93VOawz5KWG5/+UMBIiTjQa2/GrsqSHI=; b=OOQG5zJXh7z8k+3TR6Yjgr9g+PeUz2h8womZqRuoB1MalTK5mcTn6TTjYE48TGnJe8 wMkKj4xGcHRlh4jNJyKXtbUCjPFpcClwuHjrlHoMUpkPkRjxkdRGKDH+iOHAabrpEcVm s3DwRTT9CX09yx00ORjAFN4qtwN9rcOse4ky1BRmJ4boG90ig8/wZw221vbCSR3XxyVe j1enUqiq/ZcewVTKXK7th/27Zbd/CP11jIQMv+5bXChKYio5npLG/2lACmECfdzLbpoK KEqZ1ysyaPAephpeoYqPwtt0qlGo7Ipu9lgrZjrXrGbGbmxsHF53W9z5PWab3uyrkSde 17oQ== X-Gm-Message-State: AOAM532+bzuCJpah75GliLb/PXDG4dW7dzTR1+Vc025wxH7AD0Wy5c4J SlNfyOFwaFpXNC3HsdKEi7tWBl9aphVeRcJqsgXBJwE5xqA= X-Google-Smtp-Source: ABdhPJzHTIY8dKTDbutG6CqeVuUTGZC50cUAsYw+Qa0Y8zb3dKtsr1PCfgp/DR4xZ5hDPd4m3NI/uuoP4RicbhLHuc0= X-Received: by 2002:a05:6512:2283:: with SMTP id f3mr42219296lfu.568.1641375396582; Wed, 05 Jan 2022 01:36:36 -0800 (PST) MIME-Version: 1.0 References: <81fe282c-45d6-f54a-16b9-9dfffedaaa33@alec.pl> In-Reply-To: <81fe282c-45d6-f54a-16b9-9dfffedaaa33@alec.pl> Date: Wed, 5 Jan 2022 01:36:23 -0800 Message-ID: To: Aleksander Machniak Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000074d92105d4d27df3" Subject: Re: [PHP-DEV] [VOTE] User Defined Operator Overloads From: jordan.ledoux@gmail.com (Jordan LeDoux) --00000000000074d92105d4d27df3 Content-Type: text/plain; charset="UTF-8" On Wed, Jan 5, 2022 at 12:26 AM Aleksander Machniak wrote: > > - what is the performance impact? > Each operator evaluation is very slightly better than the equivalent function call, since the VM call chain is very slightly simpler, but for most purposes you can think of the performance as being the same as a method call. This is quite a bit slower than most operator evaluations (which are lightning fast compared to function calls), however this *only* affects *objects* used with operators, which currently always result in a fatal error. So in that sense, there is no performance impact. > - why "[public] operator" and not "operator function"? > As many people in this thread have pointed out, it's possible for less experienced developers to do something truly devious with this (the same way that they can with __get, __set, or __toString). I wanted to avoid using the function keyword at all, because I wanted the code itself to mentally prepare the programmer to treat these differently than arbitrary functions. As I mentioned in a previous email, some will view this as wishy-washy, but that decision was done after consulting a specialist that I know in the field of Human Centered Design (the field of designing technology so that it is used correctly by design alone). That is, in truth, my largest reason for wanting the operator keyword, but it's also something that I invested nearly two months of study and consultation into. That makes it difficult for me to correctly convey that understanding to other people here via email, so I have mostly restricted my arguments to other things. I find myself in the odd position of not really being able to dump all of the research I did here for everyone else, because frankly, no one on this list *should* need to invest a week of studying to understand an RFC. So unfortunately, my best argument in favor of this is one I can't really make, but that *is* the reason that I went this route. > - what about precedence, i.e. what happens with $a + $b * $c? there's no > clear answer > Precedence is handled by the compiler and how it handles the opcodes. That's independent of any of the changes in this RFC, since the opcodes for all the operators are the same with or without operator overloads. So the precedence will be the same if $a, $b, and $c are ints or objects, even if we later (for some reason) changed the precedence of the operators. > - why not allow the tilde operator to be used in a different context?, > e.g. in PostgreSQL it is used as a regular expression match, e.g. > $a ~ '^[a-z]+$' > This would involve changing the opcode evaluation itself, instead of just implementing a do_operation handler in zend_class_entry. It would introduce much more surface for buggy behavior and be a great deal of additional effort for that single operator. > - the Implied Operators table does not mention ~= operation. > The ~= operator does not exist in PHP because the ~ operator is a unary operator in PHP (bitwise not). See: - https://www.php.net/manual/en/language.operators.assignment.php - https://3v4l.org/N9OYF > - I don't like the Reflection API changes > Please suggest changes then. It seems probable this will not pass in this incarnation, so knowing what things to improve before bringing it back would be helpful. Jordan --00000000000074d92105d4d27df3--