Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115695 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70154 invoked from network); 11 Aug 2021 16:22:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Aug 2021 16:22:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AE7EB180088 for ; Wed, 11 Aug 2021 09:53:12 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE 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-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.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 ; Wed, 11 Aug 2021 09:53:12 -0700 (PDT) Received: by mail-qk1-f170.google.com with SMTP id e14so3100472qkg.3 for ; Wed, 11 Aug 2021 09:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=9czXXH/RAlOt69sjjC8AJF0OMELLMTnQDk5MNsWqX7s=; b=sPRdwT8sQ2S24ZzMeobIpDVLLWaVa0tDK+97p0PVF5c2A+bohsnlni4SmKM/PhY4Os 0/lCiphu2ku1AWA7I9gBAKdYCdjt72/z6ancpXX79I/DhWD81q2SPGWAd69r01CnIkHR Ddg+a250xVnzMXOHJtjVL3AgCuyQ0MmbysrRyS5VrVp4EPyBO/7nIjE9soZSSM2oiN5J 1yFLJVN1k/0Nnii9LKbnsqEYhNW4MCuGABkf4/WoOzn29QJbV6Qv7wpMZLw/8bRMVzbV gNPksaKYQiIix7QLIxCI0DPBbalDzXKBCTmDmDbE/H/fQN7qCYNHGZiFcsLLAOEjNYfK S9jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=9czXXH/RAlOt69sjjC8AJF0OMELLMTnQDk5MNsWqX7s=; b=GC+YQyx5NMGmuDIQXqnKizMnRpcgzDUiri+xLQ9Jmt0syXFIUiwWuUrDbfDq2HbvI1 duCdMwQTY4rIlDWxca8Aivasb0mqjrbNhucrsceDSUpft0uNHJxhyUN6Ht7ktC+DJHS3 OqIgRY5zGh3g8WGmqfuDYq6iCHtokbhauoVGUU8d1TlQbsRMdhji5cLV3fZjb7h42gLs 3o2y7Us0OPKy9VMJOqj6GfLEDUk2T43JbS8mLGQWSqgcVazmFv/fRHgtGVHlgrbm1VWT nLy9akKf2HjweoZIRT8+sW6sYUkBQol6/ZderomIWXG7WfGu1OFWgG5GC/jEL9CtZnQ2 5iiQ== X-Gm-Message-State: AOAM533FK/MWNdVFNDV06/nN9+1WJL0kjoon3krdvKAxiLMQd2ip42XE siPM3w7S6LslqhE3L9FjN0Q0sQ== X-Google-Smtp-Source: ABdhPJxwTfn30/fU12iSQPveALXDnITIzxjhFBoE/Wt5U0k+rwXWPi0+SSgN2t/oWjuSgUJsSM1shA== X-Received: by 2002:a37:9244:: with SMTP id u65mr34816818qkd.46.1628700789888; Wed, 11 Aug 2021 09:53:09 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id f63sm2871551qke.125.2021.08.11.09.53.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Aug 2021 09:53:08 -0700 (PDT) Message-ID: <9BCF1D9C-362A-40AF-9C7C-CC02B002BBD9@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_F2C27DF0-B167-40F1-A86F-83D8B259255C" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Date: Wed, 11 Aug 2021 12:53:07 -0400 In-Reply-To: Cc: PHP internals To: Jordan LeDoux References: <94696d46-c4e6-406a-b859-89144bff31bf@www.fastmail.com> <3D7F74C1-F1A0-4258-8EE3-3C143B6B54EB@newclarity.net> X-Mailer: Apple Mail (2.3608.120.23.2.7) Subject: Re: [PHP-DEV] Revisiting Userland Operator Overloads From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_F2C27DF0-B167-40F1-A86F-83D8B259255C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Aug 11, 2021, at 5:25 AM, Jordan LeDoux = wrote: >=20 > I want to avoid this. :) The implementations in my actual math = libraries are much more thorough and thought out. This is an example. If = people want to see something that is closer to what would actually be = done in a library, they should look at an actual library. So instead, = that's what I'll link to: >=20 > Here's the multiply method: = https://gist.github.com/JordanRL/98cceb392ba5ba943462fe574f18de51 = > Here's the translateToParts method: = https://gist.github.com/JordanRL/2c67acb3b5d3069c3a4d2f0448a480d1 = > Here's the PolynomailFunction: = https://gist.github.com/JordanRL/673e357e7f5cf63bd4554fb3161c026b = >=20 > You can think of ImmutableDecimal as Real|Imaginary, but with methods = such as $obj->isReal() and $obj->isImaginary() on it. >=20 > This is just for the __mul() method. The intent of this example is to = show the nature of the problems being solved, not to show the actual = solutions. Think of this as syntactically correct pseudo-code, not an = actual implementation. Well, I refactored not to provide an actual implementation but to try to = show the problems being solved in a manner that could be more easily = understood. But it is your RFC, so it's yours to decide how code is = presented. ---- Anyway, I'll summarize as I am going to try to wrap up my participation = in this topic, at least for now: 1. I argue that it would likely be a mistake to add general purpose = operator overloading to classes in PHP (or at least before a lot of = experience with #2.) 2. However, I recognize there are use-cases which beg for operator = overloads I think PHP. And I believe those use-cases are finite: money, = the math examples, and units[1] being three (3) subsets. I think PHP = would be better served by adding those use-cases as standard library = classes[2] instead of adding general purpose operator overloading to the = language. 3. However, *if* there is strong consensus that we should add general = purpose operator overloading then I argue that it should be limited to = "value" objects, which currently would mean only classes where all = public and protected properties are read-only[3]. 4. And even if we do #3 that is no reason for us not to consider also = doing (at least some of) #2. #fwiw -Mike [1] https://www.nist.gov/pml/weights-and-measures/metric-si/si-units = [2] I mean, how great would it be to have a Length class with unit = conversions built into PHP? Or a Money class that all libraries that = deal with Money would be able to interoperate with? Having these = non-changing concepts built-in to PHP would be a strong reason = developers to choose PHP over other options like Node where they have to = manage tons of ever-changing and incompatible 3rd party dependencies. = Better that than 10+ different userland implementations of the same = bedrock concepts, many of which are incomplete and all of which are = incompatible with each other. [3] Yes, private property values could be changed by methods and thus = leak to the outside. But that could be considered an anti-pattern. If = said private property(s) (partially) represent the state of the object = and are not readonly then we could simply recognize that as an unchecked = bad practice. --Apple-Mail=_F2C27DF0-B167-40F1-A86F-83D8B259255C--