Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116712 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91642 invoked from network); 21 Dec 2021 23:44:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Dec 2021 23:44:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A0678180510 for ; Tue, 21 Dec 2021 16:47:56 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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-ua1-f43.google.com (mail-ua1-f43.google.com [209.85.222.43]) (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 ; Tue, 21 Dec 2021 16:47:56 -0800 (PST) Received: by mail-ua1-f43.google.com with SMTP id y23so1173998uay.7 for ; Tue, 21 Dec 2021 16:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=tor2PX6daBH5BcHZmUA4hIIGT/eIENVTLEubHPp3kbE=; b=FaVcIcWPY9kCSD5/HZ4D/NGhd9T5Jwfhqm7Z7NKliSLisBt8DpG3sh1oxKoVi/GKLR BKt8XqpQz6Z93cqH2R6ypdVqJOItWTiAnzwsICAqeaprRwyhUYA50AJB0tT8wnDVen/h vVRjIYJSyZtX2zUt6nEUifeAnjDngAJmU1Yo/AXvgdoCgDi2agKvviwN4SFrO2hS5Igc BNXcgH9WsQrVgAQ6Bqpo4vu6C7/gw7NJ1KSmuSHx5d5XKFzrgJ3d5MB8QI/QMOMnwGcB VQ7qjYZ1gWI9bie+yQrTMVsYwB6otna4VmJ6jwn4MAQOIgaoIROGI0xg3ByB9Xc/d6Cm 4Gjg== 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:content-transfer-encoding; bh=tor2PX6daBH5BcHZmUA4hIIGT/eIENVTLEubHPp3kbE=; b=BCsh9pflRkq5mrIP/D85kALU/2ZghBEt0VNw01hJdahxnjgW8/j++R/m63EQIUyTA3 CkJFlAsnWgtI47nU7V5TCearg5qoUZ2OjyANhOqu8ZD+8AQaAfSv5Bu1f68cU3A7ewxI 3SA60xweEaJXndoioE79vKGXFtAElARszgZdpj+eKllJW/sXaaPRCWZQtBjxkXkXYtMO UI8X5xl8Vto+xB4vKzAmeq5xNotcZFfDK9gg2my5MivcEiUVCq9oaZbTUtdOAQ7Iuh1z Lu6bgwVvoIik+eIltLsHc+Wk9InxT4oXo7+p/DLcvVUMgmkCApmDXldgylznEzPCI5Z2 AO0Q== X-Gm-Message-State: AOAM533iAmvIKoolHeH7RTTHtRt6oGuRtqePAnuXK/S4kXPxgsAv9JQb KJqjZEcj8bkwanHAYwsG84QV55XVqh9ltwfMVd9svw== X-Google-Smtp-Source: ABdhPJyNlvHgzQ0s8bHwwsm5dbpueP+q+OtC0xU/Eaat7uPMQvuloAH0BQ5WkJkE2POlHJdeo1MUXrOLWOXA0yhQMrg= X-Received: by 2002:a05:6102:c0e:: with SMTP id x14mr321874vss.24.1640134075186; Tue, 21 Dec 2021 16:47:55 -0800 (PST) MIME-Version: 1.0 References: <44b3fb4b-4693-1639-c8c0-5e17296c196e@gmail.com> <4b58c011-ed87-ba87-201d-0cf8e4116c6f@processus.org> <67431363-cd1e-9575-7d51-0f4d265d05b9@gmail.com> In-Reply-To: Date: Wed, 22 Dec 2021 01:47:44 +0100 Message-ID: To: Jordan LeDoux Cc: Dan Ackroyd , Stanislav Malyshev , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] User Defined Operator Overloads (v0.6) From: andreas@dqxtech.net (Andreas Hennings) On Tue, 21 Dec 2021 at 23:20, Jordan LeDoux wrote= : > > > > On Tue, Dec 21, 2021 at 5:47 AM Andreas Hennings wr= ote: >> >> I see the "Implied Operators" section. >> I assume this means that a new instance will be created, and stored on >> the same variable, _if_ the original operator is written in an >> immutable way (which it should be)? >> >> E.g. >> >> $money =3D new Money(5); >> $orig =3D $money; >> $m2 =3D $money + new Money(2); >> assert($money =3D=3D=3D $orig); // Checking object identity. >> assert($m2 !=3D=3D $orig); >> $money +=3D new Money(1); // Equivalent to $money =3D $money + new Mone= y(1); >> assert($money !=3D=3D $orig); >> assert($orig->amount() =3D=3D=3D 5); >> >> I think we need a strong recommendation to implement operators as immuta= ble. > > > Yes. The documentation for operator overloads should be much larger than= this RFC, and if this passes my focus for the rest of 8.2 will be on two t= hings: > > - Working on a few smaller follow up RFCs (sorting/ordering enum, polymor= phic handler resolution) > - Working to help on the documentation of this feature > > All of the examples in the documentation should be for immutable implemen= tations, and there should be an explicit recommendation for immutable imple= mentations as well. With operators, mutable versions are created with the o= perators under the "Implied" section instead of by creating an immutable im= plementation of the operator itself. Right. But even for the "implied" operators, I would say "mutable" should refer to the variable, but not to the object. This is what I tried to communicate with the code example. > > Jordan